UITableViewCellAccessoryCheckmark 单选、多选

单选

1、第一步

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

...  

cell.accessoryType  = UITableViewCellAccessoryNone;   //初始化不显示

...

return cell;

}

2、第二步

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[tableView reloadData];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

cell.accessoryType = UITableViewCellAccessoryCheckmark;   //显示你所要的样式

}

多选

1、第一步

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

...

cell.accessoryType  = UITableViewCellAccessoryNone;   //初始化不显示

...

return cell;

}

2、第二步

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (cell.accessoryType == UITableViewCellAccessoryNone) {

cell.accessoryType = UITableViewCellAccessoryCheckmark;

}else{

cell.accessoryType = UITableViewCellAccessoryNone;

}

}

你可能感兴趣的:(UITableViewCellAccessoryCheckmark 单选、多选)