解决cell循环利用造成的重复勾选
@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循环利用造成的重复勾选的更多相关文章
- 关于UITableViewCell的循环利用--面向初学者
UITableViewCell的重复利用机制有效地节省内存开销和提高程序性能. 1 原理 tableView拥有一个缓存池,存放未在使用(没有显示在界面)的cell. tableView有一行cell ...
- iOS开发:一个瀑布流的设计与实现(已实现缓存池功能,该功能使得瀑布流cell可以循环利用)
一个瀑布流的实现有三种方式: 继承自UIScrollView,仿写UITableView的dataSource和delegate,创造一个缓存池用来实现循环利用cell 写多个UITableview( ...
- 实现UITableView循环利用
tableViewUITableView循环利用 前言 大家都知道UITableView,最经典在于循环利用,这里我自己模仿UITableView循环利用,写了一套自己的TableView实现方案,希 ...
- iOS开发小技巧--TableView中headerView的循环利用,以及自定义的headerView
一.首先要搞清楚,tableView中有两种headerView,一个是tableHeaderView,另一个是headerView.前者就一个;后者根据session决定个数 headerView的 ...
- iOS开发UI篇—无限轮播(循环利用)
iOS开发UI篇—无限轮播(循环利用) 一.无限轮播 1.简单说明 在开发中常需要对广告或者是一些图片进行自动的轮播,也就是所谓的无限滚动. 在开发的时候,我们通常的做法是使用一个UIScrollV ...
- 解决NSTimer循环引用Retain Cycle问题
解决NSTimer循环引用Retain Cycle问题 iOS开发中以下的情况会产生循环引用 block delegate NSTimer 循环引用导致一些对象无法销毁,一定的情况下会对我们横须造成影 ...
- iOS边练边学--UITableView性能优化之三种方式循环利用
一.cell的循环利用方式1: /** * 什么时候调用:每当有一个cell进入视野范围内就会调用 */ - (UITableViewCell *)tableView:(UITableView *)t ...
- 解决NSTimer循环引用
NSTimer常见用法 @interface XXClass : NSObject - (void)start; - (void)stop; @end @implementation XXClass ...
- Oracle中使用Table()函数解决For循环中不写成 in (l_idlist)形式的问题
转: Oracle中使用Table()函数解决For循环中不写成 in (l_idlist)形式的问题 在实际PL/SQL编程中,我们要对动态取出来的一组数据,进行For循环处理,其基本程序逻辑为: ...
随机推荐
- HTML第七天学习笔记
今天主要是学习如何使用JS,第一个就是先是使用JS输出"Hello world" <!doctype html> <html lang="en" ...
- Hanganalyze 使用
It is important to find the that the reason hangs the database. How can we do, is a headache thing. ...
- Thread message loop for a thread with a hidden window? Make AllocateHwnd safe
Thread message loop for a thread with a hidden window? I have a Delphi 6 application that has a thre ...
- TL-WR703 USB不稳定/当前的总结
http://see.sl088.com/wiki/WR703_USB%E4%B8%8D%E7%A8%B3%E5%AE%9A/%E5%BD%93%E5%89%8D%E7%9A%84%E6%80%BB% ...
- Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力
B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...
- .net MVC 碰到的问题
1:问:回车会默认会触发页面从左边至右,从上到下索引位置第一的按钮事件.如何取消? 答:在不需要触发按钮事件的按钮中加一个属性:UseSubmitBehavior="false" ...
- CF B. Kolya and Tandem Repeat
Kolya got string s for his birthday, the string consists of small English letters. He immediately ad ...
- .net处理JSON简明教程
.net处理JSON简明教程 Json.Net是.net中的一种流行的高性能的JSON框架. 特点 灵活的JSON序列化转化.net对象为JSON字符串.和把JSON字符串转换为.net对象. 手动读 ...
- [Angular2 Router] Load Data Based on Angular 2 Route Params
You can load resource based on the url using the a combination of ActivatedRouteand Angular 2’s Http ...
- .net 调用C++类库
事实上这一直是个非常无解的问题.最好的办法是将C++类库写成COM. 可是有时候往往不能这个做.那就仅仅有两种办法:转成C函数形式或者Manage C++封装. 下文就介绍了这两种方法. 原帖:htt ...