代码之家  ›  专栏  ›  技术社区  ›  Ben Clayton

UITableView:如何在选择时显示UITableViewCellAccessoryDetailDisclosusRebutton?

  •  0
  • Ben Clayton  · 技术社区  · 15 年前

    我希望表视图中的所有行都使用uiTableViewCellAccessoryOne(例如,右侧没有按钮),除非选中它们,此时我希望使用uiTableViewCellAccessoryDetailDisclosusRebutton。例如,一次只有一行(如果没有选择,则为无)具有按钮。

    这有可能吗?执行实现accessorytypeforrowwithindexpath的常规操作似乎不会动态工作——例如,无论选择什么,它只被调用一次。

    谢谢

    2 回复  |  直到 15 年前
        1
  •  1
  •   Ben Gottlieb    15 年前

    如果更改单元格的内容,则需要在TableView上调用-ReloadRowSatindexpaths:WithRowAnimation:。

        2
  •  3
  •   Ben Clayton    15 年前

    请注意其他人尝试此操作。accessorytypeforrowwithindexpath委托方法现在已贬值,如果尝试此方法,将收到此消息:

    警告:使用旧单元格布局到期 委托执行 表视图:accessorytypeforrowwithindexpath: 在。拜托 删除此的实现 方法并设置单元格属性 附件类型和/或 编辑AccessoryType以移动到 新单元格布局行为。这种方法 以后不会再打电话了 释放。

    相反,在UITableViewCell子类中实现setSelected方法。例如

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
    
    if (selected) {
        self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    } else {
        self.accessoryType = UITableViewCellAccessoryNone;
    }
    

    ..然后使用ReloadRowSatindePaths:WithRowAnimation方法,如上所述。

    推荐文章