adding accessorytype without using the delegates
is there a way to add cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; to each row in a table without using delegate tableView functions?(the reason for this is a bit complicated..)
im thinking on stuff like
for(UITableViewCell *cell in TheTable开发者_如何学运维){
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
but this wont work.. any ideas?
ty in advance!
You will never have access to all the cells from the UITableView
object. You can access the visible cells like @Jhaliya mentioned. Of course your best approach here is to have a BOOL
instance variable to keep track of whether cells have the detail disclosure button and flip them.
BOOL isDetailDisclosureAccessoryVisible;
In tableView:cellForRowAtIndexPath:
,
if ( isDetailDisclosureAccessoryVisible ) {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
When you want to make them available,
isDetailDisclosureAccessoryVisible = YES;
[TheTable reloadRowsAtIndexPaths:[TheTable indexPathsForVisibleRows]
WithRowAnimation:UITableViewRowAnimationNone]; //Choose an appropriate animation here.
You could do it by accessing the UITableViewCell
in an functions defined by you.
There are number of function in UITableView
which you could use to access the UITableViewCell
outside the delegate functions.
- (NSArray *)visibleCells;
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
- (NSArray *)indexPathsForVisibleRows;
To access a cell for a given indexPath use the below method.
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
For more read UITabelView apple doc.
精彩评论