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;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,951评论 3 38
  • //设置行高 (CGFloat)tableView:(UITableView *)tableView height...
    俊月阅读 5,059评论 0 1
  • { 24、Sqlite数据库 1、存储大数据量,增删改查,常见管理系统:Oracle、MSSQLServer、DB...
    CYC666阅读 4,531评论 0 1
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 5,313评论 9 5
  • 2017/7/28 分享一下今天的故事把,一个从农村出来的穷女孩的故事。从小在父母的严格看护下好好学习,以优异的成...
    段沛含阅读 1,183评论 1 1