UITableViewの使い方
ViewControllerをUITableViewDelegateとUITableViewDataSourceに準拠させておく
viewDidLoad内でUITableViewのDelegateとDataSourceをselfに設定
以下のメソッドを実装
- didSelectRowAtIndexはセルの選択時に呼び出される.segueを呼び出すなどの処理を行う.
- numberOfRowsInSectionは セクション内のテーブル数を設定する(実装必須)
- cellForRowAtIndexはセルの中身を設定する(実装必須)
#pragma mark -- Table View Delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Selected"); } #pragma mark -- Table View DataSoruce - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } if (indexPath.row == 0) { cell.textLabel.text = @"foo"; } else if (indexPath.row == 1) { cell.textLabel.text = @"bar"; } else if (indexPath.row) { cell.textLabel.text = @"hoge"; } return cell; }