问题描述
|
有没有一种方法可以添加cell.accessoryType = UITableViewCellAccessoryDetaildisclosureButton;
而不使用委托tableView函数访问表中的每一行?(原因有点复杂。)
我正在思考类似的东西
for(UITableViewCell *cell in TheTable){
cell.accessoryType = UITableViewCellAccessoryDetaildisclosureButton;
}
但这行不通..
有任何想法吗?
提前ty!
解决方法
您将永远无法访问“ 1”对象中的所有单元格。您可以访问可见的单元格,例如@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.
, 您可以通过在您定义的函数中访问ѭ6来完成此操作。
UITableView
中有许多功能可用于委托函数之外的UITableViewCell
中使用。
- (NSArray *)visibleCells;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
- (NSArray *)indexPathsForVisibleRows;
要访问给定indexPath的单元格,请使用以下方法。
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
有关更多信息,请阅读UITabelView苹果文档。