【问题标题】:iOS UiTableViewCell selective cells to show accessoryViewiOS UiTableViewCell 选择性单元格显示附件视图
【发布时间】:2015-04-24 17:12:33
【问题描述】:

我的问题类似于this:

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

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

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

else 
{
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

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

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

【问题讨论】:

    标签: ios uitableview accessoryview


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

    【讨论】:

    • 感谢您的帮助。你是对的,我必须重新考虑我的逻辑。我认为“细胞”是个体的,但我意识到它要么全部要么全无。
    • 终于有时间测试了,这部分解决了,但是你知道如何在 UITableViewCell *cell 初始化之前读取 cell.textLabel.text 吗?
    • 想想你想要做什么。在单元格初始化之前,您无法读取单元格文本标签的内容。但是你可以做的是从你得到它的任何地方读取文本——如果你从一个数组中获取它,你应该访问数组中相应的字符串。
    • 现在解决了 :-D 这只是我的想法在跟我开玩笑。非常感谢!
    【解决方案2】:

    您应该在 tableView:cellForRowAtIndexPath: 中执行此操作,同时设置您的 UITableViewCell

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 2020-01-01
          • 2011-10-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多