有没有一种方法可以在不使用委托tableView函数的情况下将cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;添加到表的每一行中?(原因有点复杂。)
我在想像这样的事情
for(UITableViewCell *cell in TheTable){
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}但是这是行不通的..有什么想法吗?
在ty之前!
发布于 2011-05-30 20:12:32
您将永远无法访问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. 发布于 2011-05-30 19:27:17
您可以通过访问您定义的函数中的UITableViewCell来完成此操作。
UITableView中有许多函数,您可以使用它们在委托函数之外访问UITableViewCell。
- (NSArray *)visibleCells;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
- (NSArray *)indexPathsForVisibleRows;要访问给定indexPath的单元格,请使用以下方法。
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath有关更多信息,请阅读UITabelView苹果文档。
https://stackoverflow.com/questions/6175617
复制相似问题