开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜