【问题标题】:Setting a UITableViewCell accessory type on some cells, but not all在某些单元格上设置 UITableViewCell 附件类型,但不是全部
【发布时间】:2010-03-29 22:27:15
【问题描述】:

我的 UITableViewController 中有 8 个单元正在构建。我想知道如何在第 4 和第 8 单元格上显示披露指示符。现在我正在构建它

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

虽然我完全知道它将为每个单元格添加一个披露指示符

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview


    【解决方案1】:

    使用简单的 if 语句:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        ... // do whatever
        UITableViewCellAccessoryType accessoryType = UITableViewCellAccessoryNone;
        if (indexPath.row == 3 || indexPath.row == 7) {
            accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        cell.accessoryType = accessoryType;
        ... // do whatever
    }
    

    【讨论】:

    • @Morkrom 我现在有足够的代表来自己修复它。 :)
    【解决方案2】:

    你知道 indexPath,所以为什么不只是有条件地应用披露指示符

    if((indexPath.row == 3) || (indexPath.row == 7))
    

    ?

    (当然,indexPath.row 是从 0 开始的……第 4 位是 3,第 8 位是 7。您应该使用 #defines 或其他方式将幻数排除在外。)

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      相关资源
      最近更新 更多