有没有办法添加cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 不使用委托tableView函数到表中的每一行?(原因有点复杂..)
我在考虑像
这样的东西for(UITableViewCell *cell in TheTable){
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
但这不会工作.. 任何想法?
事先提前了!答案 0 :(得分:1)
您可以通过访问您定义的函数中的UITableViewCell
来完成此操作。
UITableView
中有许多功能可用于访问委托功能之外的UITableViewCell
。
- (NSArray *)visibleCells;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
- (NSArray *)indexPathsForVisibleRows;
要访问给定indexPath的单元格,请使用以下方法。
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
更多阅读UITabelView apple doc。
答案 1 :(得分:1)
您永远无法访问UITableView
对象中的所有单元格。您可以访问@Jhaliya提到的可见单元格。当然,您最好的方法是使用BOOL
实例变量来跟踪单元格是否具有详细信息披露按钮并将其翻转。
BOOL isDetailDisclosureAccessoryVisible;
在tableView:cellForRowAtIndexPath:
,
if ( isDetailDisclosureAccessoryVisible ) {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
如果你想让它们可用,
isDetailDisclosureAccessoryVisible = YES;
[TheTable reloadRowsAtIndexPaths:[TheTable indexPathsForVisibleRows]
WithRowAnimation:UITableViewRowAnimationNone]; //Choose an appropriate animation here.