たとえば、rowDataという可変配列を作成できます。init / initWithCoder / etcメソッドで、たとえば、各ラベルのデータを含む、columnDataと呼ばれる別の可変配列を作成できます。各行のcolumnDataオブジェクトをrowDataに追加します。
cellForRowAtIndexPathメソッドの場合、次のように実行できます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
int row = [indexPath row];
int i = 0;
int nLabels = [[rowData objectAtIndex:row] count];
UILabel *label;
NSLog([NSString stringWithFormat:@"%d labels", nLabels]);
for (i = 0; i < nLabels; i++) {
NSLog([NSString stringWithFormat:@"%d", i]);
label = [[[UILabel alloc] initWithFrame:CGRectMake(cell.frame.origin.x + (i * 40), cell.frame.origin.y, 40, cell.frame.size.height)] autorelease]; //replace 40 with desired label width
label.textColor = [UIColor grayColor];
label.backgroundColor = [UIColor clearColor];
// set the label text here
[cell.contentView addSubview:label];
NSLog([NSString stringWithFormat:@"%d subviews", [[cell.contentView subviews] count]]);
}
}
return cell;
}