#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. 对想进入Unity开发新人的一些建议

    提前声明:本文只是写给那些非职业游戏开发人士,只面向那些在校本科生,或已就业但无unity背景的同学们,当然是面对程序员方向的.本人刚工作也没多久,资历尚浅,之前在网上有一位同学让我谈谈一些想法,所以 ...

  2. 无需写try/catch,也能正常处理异常 (转)

    原文地址: http://www.cnblogs.com/artech/archive/2012/10/28/automatic-exception-handling-aspnet.html 对于企业 ...

  3. C++设计模式-Mediator中介者模式

    Mediator中介者模式作用:用一个中介对象来封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. UML如下: Colleage抽象同事类 ...

  4. Java使用Mysql数据库实现批量添加数据

    EmployeeDao.java //批处理添加数据 public int saveEmploeeBatch(){ int row = 0; try{ con = DBCon.getConn(); S ...

  5. CRLF和LF

    协作项目,开发环境不同(mac,window)构建过程中,命令行报错(expecting LF but only find CRLF) 打开git bash,输入 $ git config --glo ...

  6. (转)Silverlight 与 JS交互

    转自 http://www.cnblogs.com/wt616/archive/2011/10/08/2201987.html 1.Silverlight直接调用JS的函数: 这个很简单,只要在HTM ...

  7. ssh 的搭建

    struts包的下载:http://struts.apache.org/download.cgi#struts252 string包的下载: http://repo.spring.io/release ...

  8. C#读取excel数据到datatable中

    DataTable dtGBPatient = new DataTable(); string strConn;string excelName; //注意:把一个excel文件看做一个数据库,一个s ...

  9. MacOS changed System Integrity Protection status

    禁止 System Integrity Protection 按住 command + R 重启系统 进入单用户模式 启动bash工具: 输入: csrutil disable 输入:reboot 启 ...

  10. OC中property的有关属性

    property的有关属性: (1)readwrite是可读可写特征:需要生成getter方法和setter方法: (2)readonly是只读特性只会生成getter方法不会生成setter方法: ...