简体   繁体   English

UITableView:如何使UITableViewCellAccessoryDe​​tailDisclosureButton在选择时出现?

[英]UITableView: How to make the UITableViewCellAccessoryDetailDisclosureButton appear on selection?

I'd like to have all the rows on my table view use UITableViewCellAccessoryNone (eg no button on the right) unless they are selected, at which point I want to use UITableViewCellAccessoryDetailDisclosureButton. 我想让我的表视图上的所有行都使用UITableViewCellAccessoryNone(例如,右侧没有按钮),除非选中它们,这时我要使用UITableViewCellAccessoryDe​​tailDisclosureButton。 Eg only one row (or none if there's no selection) has the button at a time. 例如,一次只有一行(如果没有选择,则没有)。

Is this possible? 这可能吗? Doing the usual thing of implementing accessoryTypeForRowWithIndexPath doesn't seem to work dynamically - eg it only gets called once regardless of what's selected. 做通常的事情来实现AccessoriesTypeForRowWithIndexPath似乎并不动态-例如,无论选择什么,它只会被调用一次。

Thanks 谢谢

Note for others trying this.. the accessoryTypeForRowWithIndexPath delegate method is now depreciated, you'll get this message if you try it: 请注意其他尝试此方法的人。.现对装饰品的typeTypeRorWithIndexPath委托方法进行了折旧,如果尝试,将得到以下消息:

WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in . 警告:由于使用tableView:accessoryTypeForRowWithIndexPath:in的委托实现,因此使用旧单元格布局。 Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. 请删除您对这种方法的实现,并设置单元格属性AccessoriesType和/或editingAccessoryType以移动到新的单元格布局行为。 This method will no longer be called in a future release. 在将来的版本中将不再调用此方法。

Instead, implement the setSelected method in your UITableViewCell subclass.. eg 而是在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;
}

..then use the reloadRowsAtIndexPaths:withRowAnimation method as described above. ..然后使用如上所述的reloadRowsAtIndexPaths:withRowAnimation方法。

如果更改单元格的内容,则需要在表视图上调用-reloadRowsAtIndexPaths:withRowAnimation:。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM