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> & ...
随机推荐
- OpenCV的数据类型---Cv
CvScalar就是一个包含四个元素的结构体变量. CvScalar定义可存放1—4个数值的数值,其结构如下. typedef struct CvScalar{ double val[4];}C ...
- [PAT]素因子分解(20)
#include "stdio.h" #include "math.h" long Prime(long); long PrimeCount(long,long ...
- 在windows编译MariaDB
OS: Windows XP sp3 IDE: VS2010 MariaDB: V5.5 (到目前为止2016.5,中文域(.cn)只有清华大学 TUNA 镜像源可用) (.tar.gz为源码:.zi ...
- js拖动层原形版
脚本文件: function JzDrag(moveDivId, moveDivHandle) { // var me = this; this.M = false; //是否在移动对象 this.D ...
- Android基础开发文档汇总
一.Android 基本组件 1. Android中PackageManager使用示例 : http://blog.csdn.net/qinjuning/article/details/68678 ...
- 二模12day2解题报告
T1.笨笨玩糖果(sugar) 有n颗糖,两个人轮流取质数颗糖,先取不了的(0或1)为输,求先手能否必胜,能,输出最少几步肯定能赢:不能,输出-1. 一开始天真的写了一个dp,f[i]表示i颗糖最少取 ...
- 在win7下将CapsLock按键变成esc
我喜欢用vim来编辑,经常要按到esc,但是去按那个按键确实比较的远,而且CapsLock这个按键对我来说着实有些鸡肋,所以就想在win7上也能像ubuntu那样把capslock映射为esc,在网上 ...
- JUC.Lock(锁机制)学习笔记[附详细源码解析]
锁机制学习笔记 目录: CAS的意义 锁的一些基本原理 ReentrantLock的相关代码结构 两个重要的状态 I.AQS的state(int类型,32位) II.Node的waitStatus 获 ...
- 4、C#进阶:MD5加密、进程、线程、GDI+、XML、委托
MD5加密 将字符串进行加密,无法解密.网上的解密方式也都是在库里找,找不到也没有. 1 protected void Page_Load(object sender, EventArgs e) 2 ...
- SIGABRT的可能原因
常见原因: 第三方库如glic检测到内部错误或者破坏约束条件 3种可能1.double free/free 没有初始化的地址或者错误的地址2.堆越界3.assert