@interface ProfessionViewController (){
NSMutableArray *_professionArray;//cell模型数组
NSMutableArray *_selectArray; //已选中的cell数组
}

- (void)viewDidLoad{

  //初始化已选中的cell数组
_selectArray = [NSMutableArray array];
} #pragma mark 当cell被选中时调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //获取当前选中的cell模型
Profession *profession = _professionArray[indexPath.section];
//获取当前选中的cell模型中的title
NSString *title = profession.trade[indexPath.row];
  if ([_selectArray containsObject:title]) {
//之前是选中,现在取消选中
[_selectArray removeObject:title];
}else{
//之前未选中,现在选中
[_selectArray addObject:title];
}
  //刷新被选中的cell  
  [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
}

#pragma mark  设置每一行cell显示的内容

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

//定义循环利用标识

static NSString *identifier = @"profession";

_cell = [tableView dequeueReusableCellWithIdentifier:identifier];

//如果cell为空

if (!_cell) {

_cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];

}

//取得cell模型数组

Profession *profession = _professionArray[indexPath.section];

//取得cell模型数组中的title

NSString *title = profession.trade[indexPath.row];

//取得行业并设置给cell

  _cell.textLabel.text = title;

//判断当前title是否在已选中的数组中

if ([_selectArray containsObject:title]) {

//打钩

_cell.accessoryType = UITableViewCellAccessoryCheckmark;

}else{

//不打钩

_cell.accessoryType = UITableViewCellAccessoryNone;

}

return _cell;

}


解决cell循环利用造成的重复勾选的更多相关文章

  1. 关于UITableViewCell的循环利用--面向初学者

    UITableViewCell的重复利用机制有效地节省内存开销和提高程序性能. 1 原理 tableView拥有一个缓存池,存放未在使用(没有显示在界面)的cell. tableView有一行cell ...

  2. iOS开发:一个瀑布流的设计与实现(已实现缓存池功能,该功能使得瀑布流cell可以循环利用)

    一个瀑布流的实现有三种方式: 继承自UIScrollView,仿写UITableView的dataSource和delegate,创造一个缓存池用来实现循环利用cell 写多个UITableview( ...

  3. 实现UITableView循环利用

    tableViewUITableView循环利用 前言 大家都知道UITableView,最经典在于循环利用,这里我自己模仿UITableView循环利用,写了一套自己的TableView实现方案,希 ...

  4. iOS开发小技巧--TableView中headerView的循环利用,以及自定义的headerView

    一.首先要搞清楚,tableView中有两种headerView,一个是tableHeaderView,另一个是headerView.前者就一个;后者根据session决定个数 headerView的 ...

  5. iOS开发UI篇—无限轮播(循环利用)

    iOS开发UI篇—无限轮播(循环利用) 一.无限轮播  1.简单说明 在开发中常需要对广告或者是一些图片进行自动的轮播,也就是所谓的无限滚动. 在开发的时候,我们通常的做法是使用一个UIScrollV ...

  6. 解决NSTimer循环引用Retain Cycle问题

    解决NSTimer循环引用Retain Cycle问题 iOS开发中以下的情况会产生循环引用 block delegate NSTimer 循环引用导致一些对象无法销毁,一定的情况下会对我们横须造成影 ...

  7. iOS边练边学--UITableView性能优化之三种方式循环利用

    一.cell的循环利用方式1: /** * 什么时候调用:每当有一个cell进入视野范围内就会调用 */ - (UITableViewCell *)tableView:(UITableView *)t ...

  8. 解决NSTimer循环引用

    NSTimer常见用法 @interface XXClass : NSObject - (void)start; - (void)stop; @end @implementation XXClass ...

  9. Oracle中使用Table()函数解决For循环中不写成 in (l_idlist)形式的问题

    转: Oracle中使用Table()函数解决For循环中不写成 in (l_idlist)形式的问题 在实际PL/SQL编程中,我们要对动态取出来的一组数据,进行For循环处理,其基本程序逻辑为: ...

随机推荐

  1. DevExpress控件使用经验总结

    转自:http://www.cnblogs.com/wuhuacong/archive/2011/08/31/2161002.html

  2. HttpContext及HttpContext.current

    慎用System.Web.HttpContext.Current http://www.cnblogs.com/david1989/p/3879201.html 线程编程中用到HttpContext. ...

  3. uva10327 - Flip Sort

    Flip Sort Sorting in computer science is an important part. Almost every problem can be solved effec ...

  4. li中包含span,在IE6、IE7下会有3pxbug

    如果给每个li里面加个span标签的话,在IE6,IE7下看,li与li之间的距离就会多了3px. 解决方法:在li中加vertical-align:middle; <div class=&qu ...

  5. android一些系统相关的东西

    添加快捷方式和删除快捷方式: private void addShortcut() { Intent shortcut = new Intent( "com.android.launcher ...

  6. Android 开发中使用Intent传递数据的方法

    Activity之间通过Intent传递值,支持基本数据类型和String对象及 它们的数组对象byte.byte[].char.char[].boolean.boolean[].short.shor ...

  7. js获取非行间样式/定义样式

    <!--DOCTYPE html--> <html> <head> <meta charset="utf-8" /> <sty ...

  8. linux 体系结构知识 博客

    http://blog.csdn.net/haiross/article/category/1488205/3

  9. #import与@class的区别

    转自:http://www.cnblogs.com/jqyp/archive/2012/01/13/2321707.html 1.import会包含这个类的所有信息,包括实体变量和方法,而@class ...

  10. [转]SQL快速入门

    原文出处:http://blog.csdn.net/xxd851116/article/details/5688263 一.基础 1.说明:创建数据库CREATE DATABASE database- ...