忍者ブログ

[PR]

2024年04月26日
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

セルの各行に表示するテキスト

2008年11月19日
テーブルの各行に表示するテキストはcellForRowAtIndexPathで知らせます。この命令の引数はindexPathだけですが、indexPathにはindexPath.sectionにセクションのインデックス、indexPath.rowに行のインデックスがそれぞれ格納されています。ですから、indexPath.sectionとindexPath.rowで場合分けをしてあげれば良いのです。デフォルトの設定だと、各セルには1行のテキストが入ります。テキストの中身はcell.textに入れて、最後にcell全体を返します。例は長くなるので途中を省略します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.section) {
case 0: // 一番上のセクションです
switch (indexPath.row) {
case 0: // テーブルの1行目です
cell.text = @"一番上のセクションで一番上の表示項目です";
break;
case 1: // テーブルの2行目です
cell.text = @"一番上のセクションで2番目の表示項目です";
break;
} // 一番上のセクション終了
case 1: // 2番目のセクションです 
(途中略)
} // 4番目のセクション終了 
}
return cell;
}

 
PR
Comment
  Vodafone絵文字 i-mode絵文字 Ezweb絵文字
Trackback
トラックバックURL: