#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选中后进入重用池出来选中状态消失的更多相关文章

  1. iView中Tree组件children中动态checked选中后取消勾选再选中无效问题

    如题,我有一个Tree组件,动态更新check选中子级列表的时候,取消勾选了再点击选中时复选框样式不是勾选状态,但是数据已经有了. 对此解决方案是:将初始化时Tree组件data数据深拷贝一遍再去判断 ...

  2. 使用element-ui的el-menu导航选中后刷新页面保持当前选中

    <el-menu :default-active=‘$route.path‘ :router=‘true‘ :unique-opened=‘true‘ :default-openeds=&quo ...

  3. HTML页面表单输入框去掉鼠标选中后边框变色的效果

    标题说的有些含糊,实在不知道怎么描述了,就简单说一下吧,一个最简单的表单,代码如下,没有任何样式和名字, <!DOCTYPE html> <html> <head> ...

  4. js页面文字选中后分享到新浪微博实现

    demo您可以狠狠地点击这里:js文字选中分享到新浪微博demo 方法与代码 选中即分享的功能看上去比较高级,其实实现是相当简单的.其中的会让人头大,一般人也不感兴趣的原理这里就直接跳过.这个js文字 ...

  5. a标签文字选中后的颜色样式更改

    ::selection 选择器,选择被用户选取的元素部分.是css3的用法,讲真,我觉得这个东西没必要特地去写.因为选中样式默认的会根据你的背景颜色还有字体color来设置颜色 这是我默认的样式

  6. jquery操作checkBox 一次取消选中后不能再选中

    $("input[type='checkbox']").each(function(){ $(this).attr("checked","checke ...

  7. jQuery获取radio选中后的文字

    原文链接:http://blog.csdn.net/zhanyouwen/article/details/51393216 jQuery获取radio选中后的文字转载 2016年05月13日 10:3 ...

  8. C#TreeView节点选中后失去焦点时改变节点背景色

    C#TreeView节点选中后失去焦点时改变节点背景色 在使用TreeView控件时候,单击一个节点,当鼠标聚焦到别的地方的时候,之前点击的这个节点就看不清楚了 举例截图 单击后           ...

  9. js设置下拉框选中后change事件无效解决

    下拉框部分代码: <select id="bigType"> <option value="">请选择</option> & ...

随机推荐

  1. Google App Engine, Python2.7的UnicodeDecodeError bug

    在跟Web Development,要在Google App Engine上写作业,出师不利,遇到以下bug: 2014-05-06 16:14:17 Running command: "[ ...

  2. 关于tomcat的热部署

    在做java web开发时,常用的服务器就是tomcat了.如果tomcat不能实现热部署,那么恐怕每次更改文件进行发布就尤其费时了. 热部署定义:在未改变class文件的签名的前提下,文件的修改是不 ...

  3. ssh整合需要那些jar

    struts2  commons-logging-1.0.4.jar -------主要用于日志处理 freemarker-2.3.8.jar ------- 模板相关操作需要包 ognl-2.6.1 ...

  4. linux 查看系统信息

    一.查看内存信息 可以使用free命令显示系统的物理内存和交换分区的总量,以及已使用的.空闲的.共享的.在内核缓冲内的和被缓存的内存数量. 使用free命令可以显示计算机系统的内存容量. [root@ ...

  5. 1.3 Makefile 工程管理

    1. 为什么得用Makefile 单步命令生成led.bin [root@cfm880 lesson1]# cd .. [root@cfm880 Part1]# mkdir lesson3 [root ...

  6. LoadRunner测试结果分析01 转载至zhangzhe的新浪博客

    LoadRunner测试结果分析之我见 LoadRunner生成测试结果并不代表着这次测试结果的结束,相反,这次测试结果的重头戏才刚刚开始.如何对测试结果进行分析,关系着这次测试的成功与否.网上关于L ...

  7. V8 data struct

    参考: [1]. 使用 Google V8 引擎开发可定制的应用程序: http://www.ibm.com/developerworks/cn/opensource/os-cn-v8engine/ ...

  8. Android 调用系统联系人界面的添加联系人,添加已有联系人,编辑和修改。

    一.添加联系人 Intent addIntent = new Intent(Intent.ACTION_INSERT,Uri.withAppendedPath(Uri.parse("cont ...

  9. Winform Textbox MultiLine和WordWrap属性的使用

    突然用到,有些不明白,零乱记录下: 1.MultiLine属性为True时,Dock属性Fill值才能达到所需效果 2.MultiLine属性为False时,WordWrap属性也是无效果的,同1,T ...

  10. C++ 编译报错

    vs编译错误描绘如下: 1>f:\company\newphone\softphoneservice\softphoneservice\EventS.h(13): error C2143: 语法 ...