UITableViewの使い方

  1. ViewControllerをUITableViewDelegateとUITableViewDataSourceに準拠させておく

  2. viewDidLoad内でUITableViewのDelegateとDataSourceをselfに設定

  3. 以下のメソッドを実装

    1. didSelectRowAtIndexはセルの選択時に呼び出される.segueを呼び出すなどの処理を行う.
    2. numberOfRowsInSectionは セクション内のテーブル数を設定する(実装必須)
    3. 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;
}