0

我使用 a 创建了一个选项菜单,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;
}
4

2 回答 2

2

UITableViewCellStyleValue2不包括图像:

单元格左侧带有标签的单元格样式,其文本为右对齐和蓝色;单元格右侧是另一个带有较小文本的标签,左对齐和黑色。电话/联系人应用程序使用这种样式的单元格。

您应该UITableViewCellStyleDefault改用(或设计自己的单元格)。

于 2012-05-31T06:58:37.057 回答
0

我猜你还没有创建自定义单元格,如果你的 UITableViewCell 中有这么多控件,最好有一个自定义单元格,然后访问控件的属性,你可以更改图像。你可以参考我的这篇文章。你的风格选择将不支持图像。

于 2012-05-31T07:05:11.367 回答