2011-05-30 60 views
0

有没有办法添加cell.accessoryType = UITableViewCellAccessoryDe​​tailDisclosureButton; 在表的每一行,而无需使用委托的tableView的功能呢?(这样做的原因是有点复杂..)添加accessorytype而不使用代表

IM思考的东西一样

for(UITableViewCell *cell in TheTable){ 
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
} 

但这不会工作.. 任何想法?

ty提前!

+0

什么是'TheTable'?它是'tableView'还是数组? – 2011-05-30 11:29:03

+0

TheTable只是一个tableView – Oblieapps 2011-05-30 11:43:52

+0

你是否实现了一个数据源? – 2011-05-30 11:54:38

回答

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. 
+0

嗯,谢谢你的例子代码,它的工作原理! – Oblieapps 2011-05-30 12:42:21

1

您可以通过在您定义的函数中访问UITableViewCell来实现。

UITableView中有多少个函数可用于访问委托函数外部的UITableViewCell

- (NSArray *)visibleCells; 
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect; 
- (NSArray *)indexPathsForVisibleRows; 

要访问给定indexPath的单元格,请使用下面的方法。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 

欲了解更多信息UITabelView apple doc。

+0

感谢您为功能提示! – Oblieapps 2011-05-30 12:46:02

相关问题