#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. find命令和tar命令的使用

    tar命令 tar -zcvf small.tar.gz small(目录名) (压缩) tar -zxvf small.tar.gz -C small(目录名) (解压到指定目录) find 命令 ...

  2. cocos2d-x:懒人数学函数

    做游戏开发,要用到比较多的数学计算,对于程序员来说,还是用一种懒一点的方法,cocos2d-x方便开发者投机取巧...提供了很多方便的的数学函数,方便我们的数学计算.以下是在网上收集到的一些常用的数学 ...

  3. iPad 控件 UIPopoverPresentationController 使用 iPhone可用

    UIPopoverController 在iOS9之后被废弃了,,, iOS8 新控件UIPopoverPresentationController可运用在iphone和iPad上,使用基本同 UIP ...

  4. Android驱动开发之Hello实例

    Android驱动开发之Hello实例:   驱动部分 modified:   kernel/arch/arm/configs/msm8909-1gb_w100_hd720p-perf_defconf ...

  5. CMakeLists.txt for nginx

    project(nginx) cmake_minimum_required(VERSION 2.8) aux_source_directory(. SRC_LIST) aux_source_direc ...

  6. CS 231n----Assignment1 记录

    记录下在完成cs231n的Assignment1过程中的一些东西. 1. scores是一个N*C的array,N是训练样本个数,C是标签.y是(N,)的数组,取出每一个样本对应的score,可以用以 ...

  7. ZeroC Ice 暂记

    摘自: http://weibo.com/p/1001603869896789339575 原文地址: http://www.oschina.net/question/865233_242146 吴治 ...

  8. Android 6.0权限适配

    targetSdkVersion 23以上,必须适配新的权限模式 安卓6.0及之后,权限分为三类  1.不涉及隐私的正常权限,如innernet2.危险权限 3.特殊权限 system_alert_w ...

  9. maven项目管理构建

    准备工作 在eclipse配置maven之前需要我们做好准备工作,如下: 1. 安装jdk 2. 已安装好 maven,将maven配置成功 3. 下载Eclipse,解压缩安装完成,建立工作空间.  ...

  10. 获取iPhone 联系人列表,并且根据分析得到的姓名首字母进行排序

    获取手机联系人以iOS9为分界点,大家都知道到了iOS9很多方法都更新了,好多接口都弃用,被新的接口代替.这Demo种有新旧两个接口,使用前判断当前iOS版本. 下面是Demo连接地址:Github的 ...