macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

tableView:cellForRowAtIndexPath:

INDEX>UIKit>UITableViewDataSource

テーブルに表示するセルを返します。
-(UITableViewCell *)tableView:(UITableView *)tableView
                cellForRowAtIndexPath:(NSIndexPath *)indexPath

解説

返り値

( UITableViewCell * )

引数

( UITableView * )tableView
( NSIndexPath * )indexPath

クラス

UITableViewDataSource

Instance Methods

使用可能

iPhone2.0

参照

例文

//セルを返す(表示する)

  • (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
// Create a new cell. CGRectZero allows the cell to determine the appropriate size.
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
}

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 12.0, 320.0, 25.0)] autorelease];
label.tag = 0;
label.font = [UIFont systemFontOfSize:24.0];
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor blueColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
label.text = @"あああいいいいいううううううう";

switch (indexPath.section) {
case 0: [cell.contentView addSubview:label]; break;
case 1: [cell.contentView addSubview:label]; break;
case 2: [cell.contentView addSubview:label]; break;
}


return cell;
}