1

我的问题与类似:

但是我只想为具有详细信息的单元格显示带有 DetailDisclosureButton 的附件视图。

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

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

else 
{
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

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

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

4

4 回答 4

5
- (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,那么所有单元格都将具有相同的附件类型。那是你什么?如果没有,您可能需要重新考虑您的逻辑。

于 2012-01-23T22:22:54.653 回答
2

你应该这样做tableView:cellForRowAtIndexPath:,而你正在设置你的UITableViewCell

于 2012-01-23T22:15:51.090 回答
1

将其添加到tableView:cellForRowAtIndexPath:单元格出列或初始化后

于 2012-01-23T22:17:54.153 回答
0

你可以使用这个库。配合MSCellAccessory,UITableViewCell 的accessoryType 可以很方便的自定义颜色。支持与iOS7相同的平面设计。 https://github.com/bitmapdata/MSCellAccessory

于 2015-04-24T09:12:33.233 回答