【问题标题】:one image or thumbnail for cells in a table view表格视图中单元格的一张图像或缩略图
【发布时间】:2011-09-09 03:27:54
【问题描述】:

我有以下代码,它将在 UItable 视图中显示结果以及图像。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    //create a cell
    UITableViewCell *cell = [[UITableViewCell alloc]
                             initWithStyle:UITableViewCellStyleDefault
                             reuseIdentifier:@"cell"];



    // fill it with contnets

    NSDictionary *exercise = [exercises objectAtIndex:indexPath.row];
    cell.textLabel.text = [exercise valueForKey:@"player"];

    UIImage *image = [UIImage imageNamed:@"iphone.gif"];
    cell.imageView.image = image;

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    // return it
    return cell;

}

是否有一个选项,我可以为所有单元格显示一个图像,例如。左侧有 1 张图像,右侧有 3 行。我是一个新的投标人,并且仍然掌握 iPhone 编码。请建议我如何做到这一点。谢谢。

【问题讨论】:

标签: iphone uitableview xcode4 uiimage


【解决方案1】:

是的,UITableViewCell 几乎是另一个 UIView,因此您可以向其中添加子视图并根据需要对其进行自定义。例如,如果你需要给所有单元格添加一张图片,只需将它添加到 contentView 中即可;

[cell.contentView addSubview:myImageView];

如果您的单元格需要多个自定义项,并且正在寻找高度自定义的外观,而不是标准单元格提供的通用外观,我建议您考虑创建自定义 UITableViewCell。原因是标准单元格已经布置了带有标签、图像等的 UI,您添加到其中的任何内容都可能以您不希望的方式干扰现有 UI。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 2014-01-13
    • 1970-01-01
    • 2013-01-22
    • 2015-06-25
    • 2013-06-23
    • 1970-01-01
    相关资源
    最近更新 更多