cell选中后进入重用池出来选中状态消失
#import "XXViewController.h"
@interface XXViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView *_table;
}
//定义一个数组来记录cell的是否选中的状态
@property (nonatomic, strong) NSMutableArray *arrCellSelect;
//cell的个数的数组
@property (nonatomic, strong) NSArray *arrCellCount;
@end
@implementation XXViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)creatTable{
_table = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:(UITableViewStylePlain)];
[self.view addSubview:_table];
_table.delegate = self;
_table.dataSource = self;
}
//网络请求
- (void)dataHadel{
//此处获取cell的个数数组
self.arrCellCount = [NSArray array];
self.arrCellCount = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
//遍历cell的个数,添加cell对应的选中状态
for (int i =0 ; i< self.arrCellCount.count; i++) {
[_arrCellSelect addObject:@(NO)];//一开始cell为不选中
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrCellCount.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
}
if ([[self.arrCellSelect objectAtIndex:indexPath.row] isEqual:@(NO)]) {
cell.detailTextLabel.text = @"我落选了";
}
else{
cell.detailTextLabel.text = @"我入选了";
}
cell.textLabel.text = self.arrCellCount[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [_table cellForRowAtIndexPath:indexPath];
NSIndexPath *indPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
if ([[_arrCellSelect objectAtIndex:indexPath.row] isEqual:@(NO)]) {
[_arrCellSelect replaceObjectAtIndex:indexPath.row withObject:@(YES)];
cell.detailTextLabel.text =@"我入选了";
}
else{
[_arrCellSelect replaceObjectAtIndex:indexPath.row withObject:@(NO)];
cell.detailTextLabel.text = @"我落选了";
}
[_table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indPath] withRowAnimation:(UITableViewRowAnimationNone)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
cell选中后进入重用池出来选中状态消失的更多相关文章
- iView中Tree组件children中动态checked选中后取消勾选再选中无效问题
如题,我有一个Tree组件,动态更新check选中子级列表的时候,取消勾选了再点击选中时复选框样式不是勾选状态,但是数据已经有了. 对此解决方案是:将初始化时Tree组件data数据深拷贝一遍再去判断 ...
- 使用element-ui的el-menu导航选中后刷新页面保持当前选中
<el-menu :default-active=‘$route.path‘ :router=‘true‘ :unique-opened=‘true‘ :default-openeds=&quo ...
- HTML页面表单输入框去掉鼠标选中后边框变色的效果
标题说的有些含糊,实在不知道怎么描述了,就简单说一下吧,一个最简单的表单,代码如下,没有任何样式和名字, <!DOCTYPE html> <html> <head> ...
- js页面文字选中后分享到新浪微博实现
demo您可以狠狠地点击这里:js文字选中分享到新浪微博demo 方法与代码 选中即分享的功能看上去比较高级,其实实现是相当简单的.其中的会让人头大,一般人也不感兴趣的原理这里就直接跳过.这个js文字 ...
- a标签文字选中后的颜色样式更改
::selection 选择器,选择被用户选取的元素部分.是css3的用法,讲真,我觉得这个东西没必要特地去写.因为选中样式默认的会根据你的背景颜色还有字体color来设置颜色 这是我默认的样式
- jquery操作checkBox 一次取消选中后不能再选中
$("input[type='checkbox']").each(function(){ $(this).attr("checked","checke ...
- jQuery获取radio选中后的文字
原文链接:http://blog.csdn.net/zhanyouwen/article/details/51393216 jQuery获取radio选中后的文字转载 2016年05月13日 10:3 ...
- C#TreeView节点选中后失去焦点时改变节点背景色
C#TreeView节点选中后失去焦点时改变节点背景色 在使用TreeView控件时候,单击一个节点,当鼠标聚焦到别的地方的时候,之前点击的这个节点就看不清楚了 举例截图 单击后 ...
- js设置下拉框选中后change事件无效解决
下拉框部分代码: <select id="bigType"> <option value="">请选择</option> & ...
随机推荐
- WEB页面采集器编写经验之一:静态页面采集器
严格意义来说,采集器和爬虫不是一回事:采集器是对特定结构的数据来源进行解析.结构化,将所需的数据从中提取出来:而爬虫的主要目标更多的是页面里的链接和页面的TITLE. 采集器也写过不少了,随便写一点经 ...
- Hadoop_配置_linux下编译eclipse插件
使用的hadoop版本为hadoop-1.2.1(对应的含源码的安装包为hadoop-1.2.1.tar.gz) 将hadoop和eclipse都解压在home中的用户目录下 /home/chen/h ...
- 来自 Thoughtram 的 Angular 2 系列资料
Angular 2 已经正式 Release 了,Thoughtram 已经发布了一系列的文档,对 Angular 2 的各个方面进行深入的阐释和说明. 我计划逐渐将这个系列翻译出来,以便对大家学习 ...
- php SimpleXML 例子
$txt = GetRemoteText($url); if(strlen($txt) > 0) { $xml = simplexml_load_string($txt); //获取xml if ...
- python3.x IDLE学习及基础语法(学习head first python 第一章)
1. 使用Tab键可以显示IDLE提供的一些建议: 2. Alt-N 移至下一个代码语句,Alt-P 移至上一个代码语句: 3. 列表类似于C++里的链表,有插入函数insert(位置,数据项),在列 ...
- Struts2从一个action转到另一个action的两种方法
在Struts2中,Action处理完用户请求后,将会返回一个字符串对象,这个字符串对象就是一个逻辑视图名.Struts 2通过配置逻辑视图名和物理视图之间的映射关系,一旦系统收到Action返回的某 ...
- 转@OneToMany或@ManyToOne的用法-annotation关系映射篇(上)
原文:http://blog.sina.com.cn/s/blog_6fef491d0100obdm.html 例如我们用一个例子来开启JPA的一对多和多对一的学习. 比如你去当当网上买书籍,当当网就 ...
- Scorpio-CSharp总链接
简介 源码目录介绍
- neutron floatingip-delete
- C# 利用反射给不同类型对象同名属性赋值
public class ObjectReflection { public static PropertyInfo[] GetPropertyInfos(Type type) { return ty ...