ビューコントローラー内にカスタムセルを含むテーブルビューがあります。私のテーブルビューは正しく動作します。私がやろうとしているのは、以下の画像をプログラムで開発することです。「ラベル」はカスタムのテキストで、一部の入力に応じて変化します。これら 2 つのラベルを (cellForRowAtIndexPath:) に含めて、セル内の位置を決定するにはどうすればよいですか。画像には 2 つの異なるテーブル セルが含まれています。
ストーリーボードを使用してそれを行う方法は知っていますが、xCode 4.5 で動的セルを使用しているため、プログラムで行う必要があります。
画像はインデックス セル 1 と 2 を参照しています。これまで、セルごとに 1 つのテキスト ラベルしか含めることができませんでした。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
switch ([indexPath row])
{
case 0:
{
// image cell - image resize and centred
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(30,2, 180, 180)];
imv.image=[UIImage imageNamed:@"test1.jpg"];
imv.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[cell.contentView addSubview:imv];
imv.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
cell.accessoryType = UITableViewCellAccessoryNone;
break;
}
case 1:
{
cell.textLabel.text = @"Name";
break;
}
case 2:
{
cell.textLabel.text = @"Manufacturer";
break;
}
case 3:
{
cell.textLabel.text = @"Overall Score";
break;
}
case 4:
{
cell.textLabel.text = @"Description";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
break;
}
case 5:
{
cell.textLabel.text = @"Videos";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
break;
}
}
return cell;
}
前もって感謝します