Home > Object-C | iPhone | iPhone SDK 3 > iPhoneアプリ UITableViewを試す。

iPhoneアプリ UITableViewを試す。

「Macを買うなら…」でおなじみの、秋葉館オンラインショップ
もちろん話題のiPodも本体を含め関連商品充実!
UITableView

色々と大変そうなので、避けていたのですが、

UITableViewの基礎を試してみました。
こちらをベースに色々カスタマイズしてみようと思います。

iPhone Dev Center: UITableViewDataSource Protocol Referenceより

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	self.title =@"UITableView 聖域十二宮編";

	//Tableに表示する要素
	items_ = [[NSArray alloc] initWithObjects:
			 @"1月 山羊座 - Capricornus", @"2月 水瓶座 - Aquarius",@"3月 魚座 - Pisces",
			 @"4月 牡羊座 - Aries", @"5月 牡牛座 - Taurus", @"6月 双子座 - Gemini",
			 @"7月 蟹座 - Cancer", @"8月 獅子座 - Leo", @"9月 乙女座 - Virgo",
			 @"10月 天秤座 - Libra", @"11月 蠍座 - Scorpio", @"12月 射手座 - Sagittarius",
			 nil];
}
<pre>//Viewのリリースに、要素の配列をリリース</pre>
- (void)viewDidUnload {
 [items_ release];
}

// テーブルが持っているセルの数を返す
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 return [items_ count];
}

// UiTableViewCellのインスタンスを返す
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *CellIdentifier = @"Cell";

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
 }

 // Configure the cell.

 cell.textLabel.text = [items_ objectAtIndex:indexPath.row];

 return cell;
}

TableView02

セルの選択時にアクションを発生させるには、didSelectedRowAtIndexPathメソッドをオーバライドします。

// セルの選択をハンドリングしてアクションを発生させる
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	NSString* message = [items_ objectAtIndex:indexPath.row];
	UIAlertView* alert = [[[UIAlertView alloc] init] autorelease];
	alert.message = message;
	[alert addButtonWithTitle:@"OK"];
	[alert show];
}

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://splitchin.com/tech/2010/03/14/iphone%e3%82%a2%e3%83%97%e3%83%aa%e3%80%80uitableview%e3%82%92%e8%a9%a6%e3%81%99%e3%80%82/trackback/
Listed below are links to weblogs that reference
iPhoneアプリ UITableViewを試す。 from あらびき林檎。

Home > Object-C | iPhone | iPhone SDK 3 > iPhoneアプリ UITableViewを試す。

カテゴリー
RSS あらびき林檎
スポンサー
書籍

Return to page top