“UITableViewCellAccessoryCheckmark”是一张图片吗?

时间:2011-06-15 14:09:41

标签: iphone objective-c uitableview

我需要定义一个自定义UITableViewCell,其中UITableViewCellAccessoryCheckmark位于UILabel的左侧。我应该将其定义为图像还是更智能的方式?

非常感谢,   卡洛斯

3 个答案:

答案 0 :(得分:6)

这只是关于Apple Documentation的UIView。所以只需将其定义为UIView。

首先,您必须创建自己的UITableViewCell子类(在本例中,它称为MyCell)。在此类中,在layoutSubviews方法中定义AccessoryView的框架。

- (void)layoutSubviews {
    [super layoutSubviews];
    self.accessoryView.frame = CGRectMake(0, 0, 20, 20);
}

在视图控制器中,告诉表将此类用作单元格。另外,您必须将accessoryView设置为包含图像的UIImageView。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check.png"]] autorelease];
    }
    // Configure the cell.
    return cell;
}

当用户点击单元格时,您只需更改表格单元格的accessoryView图像。

答案 1 :(得分:2)

这是UITabelViewCell标准附件类型之一,虽然您可以使用图片并通过指定{{来定义您自己的自定义附件视图类型1}}(您可以在此处添加图片)在your custom view的{​​{1}}属性中。

请参阅文档fpr accessoryType

请参阅accessoryView

的文档

答案 2 :(得分:0)

我认为使用UITableViewCellAccessoryCheckmark是不可能的。

  1. 您必须在

    中创建一个单元格
    tableView:cellForRowAtIndexPath:
    
  2. 添加自定义子视图,或返回自定义单元格

  3. 根据数据的状态使其看起来像一个复选标记或未选中。