Change the accessorytype of all the row of UITableView
I want to Change the accessory type of all the cells of UITableView on click 开发者_开发问答the bar button item.Is there any idea or code for this.
Just take an flag (a bool or something) and call reloadData on your table view. And in cellForRowAtIndexPath test for your flag and put any accessory you want.
In tableView:cellForRowAtIndexPath:
,
...
if ( selected ) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
...
On click of the bar button item,
...
selected = YES;
[self.tableView reloadRowsAtIndexPaths:[self.tableView visibleCells] withRowAnimation: UITableViewRowAnimationNone];
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// some code
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
where you can check your condition and change the accessory type of the cell to have any of the following values
typedef enum {
UITableViewCellAccessoryNone,
UITableViewCellAccessoryDisclosureIndicator,
UITableViewCellAccessoryDetailDisclosureButton,
UITableViewCellAccessoryCheckmark
} UITableViewCellAccessoryType;
精彩评论