我的问题类似于 :

但我想仅为具有详细信息的单元格显示带有 DetailDisclosureButton 的accessoryView。

我写了一些代码,但我不知道该放在哪个方法中。

if (totalcount == 0 && totalcount2 == 0)
{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

else 
{
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

Totalcount 和 TotalCount2 是两个可变数组的计数,它们告诉我单元格是否有详细信息。

如果我的问题不清楚,请追问我,谢谢。

有帮助吗?

解决方案

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* identifierString;

    if(totalCount == 0 && totalCount2 == 0) {
        identifierString = @"0";
    } else {
        identifierString = @"1";
    }

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifierString];

    if(cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:YOUR_CELL_STYLE 
            reuseIdentifier:identifierString] autorelease];

        if ([identifierString intValue] == 0) {
            cell.accessoryType = UITableViewCellAccessoryNone;
        } else {
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        }

        //do whatever setup you need to do
    }

    return cell;
}
. 虽然对我来说,似乎如果TotalCount和TotalCount2都等于0,则所有单元格将具有相同的附件类型。那是什么?如果没有,您可能希望重新思考您的逻辑。

其他提示

你应该这样做 tableView:cellForRowAtIndexPath:, ,当您设置您的 UITableViewCell

将其添加到tableView:cellForRowAtIndexPath:之后,在电池被驱逐或初始化

您可以使用此库。使用MSCellAccessory,UITableViewCell的AccessoryType可以轻松自定义颜色。支持平板设计与iOS7相同。 https://github.com/bitmapdata/mcellaccessory

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top