简体   繁体   中英

Can i set the UITableViewCellAccessoryCheckmark on BarButton?

我想在触摸Bar按钮时UITableViewCellAccessoryCheckmark tableView的所有单元格吗?

You need to set the cell accessory types in the method which you have given in the barbutton declaration.

Check this code. Follow like that

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(showChecked)];

- (void)showChecked{
isChecked = YES;
[tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


cell.accessoryType = UITableViewCellAccessoryCheckmark;

return cell;
}

use a bool variable isButtonClick;

and attach a action on barButton click says click;

so in click

-(void)click
{
  isButtonClick=YES;
  [yourTable reloadData];
}

now in cellforRowAtIndexPath

put condition

{
  //your code

  if(isButtonClick)
  {
     [yourTable setAccessoryType:UITableViewCellAccessoryCheckmark];
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM