我使用UITableViewController
创建了一个选项菜单,可以正确设置标签,但不能设置图像。
我尝试取出switch语句并使用填充了基于[indexPath row]
的正确值的数组,但也无法使其正常工作。
有什么想法吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
switch ([indexPath row]) {
case 0:
[[cell imageView] setImage:[UIImage imageNamed:@"42-photos.png"]];
[[cell textLabel] setText:@"Photos"];
break;
case 1:
[[cell imageView] setImage:[UIImage imageNamed:@"280-clapboard.png"]];
[[cell textLabel] setText:@"Videos"];
break;
case 2:
[[cell imageView] setImage:[UIImage imageNamed:@"42-info.png"]];
[[cell textLabel] setText:@"About"];
break;
default:
return cell;
break;
}
return cell;
}
答案 0 :(得分:2)
UITableViewCellStyleValue2
不包含图片:
单元格样式,单元格左侧带有标签,带有文本 这是右对齐和蓝色;在电池的右侧是 另一个标签较小的标签,左对齐和黑色。该 电话/联系人应用程序使用此样式的单元格。
您应该使用UITableViewCellStyleDefault
代替(或设计自己的单元格)。
答案 1 :(得分:0)
我猜你没有创建一个自定义单元格,如果你的UITableViewCell中有这么多控件然后访问控件属性你可以更改图像,最好有一个自定义单元格。你可以参考这个{{3我的风格选择不支持图像。