利用NSMutableDictionary  key值 来改变cell的状态

-(void)createUI{

table = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/2.0) style:UITableViewStylePlain];
    [table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];

}
-(void)createData{
  
    dataArr = [[NSMutableArray alloc]init];
    SelectArr = [[NSMutableArray alloc]init];
    
    for (int i=0; i<50; i++) {
        NSString * string = [NSString stringWithFormat:@"测试数据%d",i];
        [dataArr addObject:string];
        NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
        [dic setObject:@"no" forKey:@"key"];
        [SelectArr addObject:dic];
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * stri = @"str";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:stri];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:stri];
    }
    cell.textLabel.text = dataArr[indexPath.row];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;

//多选
    NSString * string = [NSString stringWithFormat:@"%@",SelectArr[indexPath.row][@"key"]];

//可随意更改 图片或者按钮状态
    if (![string isEqualToString:@"no"])
    {
        cell.accessoryType =UITableViewCellAccessoryCheckmark;
    }else
    {
        cell.accessoryType =UITableViewCellAccessoryNone;
    }
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 
    UITableViewCell *cell = [table cellForRowAtIndexPath:indexPath];
    cell.backgroundColor=[UIColor whiteColor];
    //多选
    NSString * string = [NSString stringWithFormat:@"%@",SelectArr[indexPath.row][@"key"]];
    if ([string isEqualToString:@"no"]) {
        [SelectArr[indexPath.row] setValue:@"yes" forKey:@"key"];
    }else{
        [SelectArr[indexPath.row] setValue:@"no" forKey:@"key"];
    }

//刷新tableview 改变点击状态
    [table reloadData];
}

UITableview cell 的多选的更多相关文章

  1. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  2. Why does uitableview cell remain highlighted?

    What would cause a tableview cell to remain highlighted after being touched? I click the cell and ca ...

  3. UITableView cell中label自动换行和自定义label自动换行

    换行的前提必须是有足够的高度 才能换 否则不显示超出部分 所以,在设置label换行的时候 要考虑cell的高度,cell的高度也要变化,废话不多说,来段代码: cell.label.text=[di ...

  4. UITableView Cell 弹簧动画效果

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...

  5. Swift - UIView,UItableView,Cell设置边框方法

    // 设置边框的宽度 cell.layer.borderWidth = 1 // 设置边框的颜色 cell.layer.borderColor = UIColor.blackColor().CGCol ...

  6. UITableview cell中多个按钮

    xib的 //不使用这种- (IBAction)button:(UIButton *)sender; //使用这种 @property (weak, nonatomic) IBOutlet UIBut ...

  7. UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法

    如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...

  8. 【iOS】UITableview cell 顶部空白的n种设置方法

    我知道没人会主动设置这个东西,但是大家一定都遇到过这个问题,下面总结下可能是哪些情况: 1, self.automaticallyAdjustsScrollViewInsets = NO;  这个应该 ...

  9. 设置cell背景色和选中色

    // 设置cell的背景色 UIView *bg = [[[UIView alloc] init] autorelease]; bg.backgroundColor = [UIColor colorW ...

随机推荐

  1. zsh(yum装包的时候,有时候会不行)

    [root@GIT ~]# yum search zsh =============================== N/S Matched: zsh ====================== ...

  2. Java查询网址

    Java在线帮助文档: http://docs.oracle.com/javase/8/docs/technotes/guides/desc_jdk_structure.html Java小知识讲解: ...

  3. Codeigniter:如何写一个好的Model

    本文是关于在Code Igniter PHP MVC框架中如何编写Model方法. CRUD 方法 CRUD 是Create, Retrieve, Update, and Delete的缩写. 这些是 ...

  4. [杂]SQL Server 之 Service Broker

    由于某些原因,我们的缓存依赖于数据库,而数据库反向通知需要依赖和使用ServiceBroker, 由于Deploy的人往往不是很清楚这个SB需要如何部署,特此记录. 判断数据库是否启用了Service ...

  5. python网页爬虫

    1. 静态页面爬取 这类最简单啦,右键->查看页面源码时,想下载的信息都能够显示在这里,这时只需要直接down页面源码,代码如下: # Simple open web import urllib ...

  6. Libsvm自定义核函数【转】

    1. 使用libsvm工具箱时,可以指定使用工具箱自带的一些核函数(-t参数),主要有: -t kernel_type : set type of kernel function (default 2 ...

  7. 5.AsyncHttp、post

    httpClient // 网络访问请求 new Thread(new Runnable() { @Override public void run() { String url = "ht ...

  8. Java的线程模型

    并发不一定要依赖多线程(如PHP中很常见的多进程并发),但是在Java里面谈论并发,大多数都与线程脱不开关系. 线程是比进程更轻量级的调度执行单位,线程的引入,可以把一个进程的资源分配和执行调度分开, ...

  9. PDA移动开单系统-PDA开单,手机开单,开单APP,移动开单,移动POS开单

    仓库的送货员.收货员.仓管员人手一部PDA,门店可以直接PDA扫描商品下订单或输入编号.拼音码等下订单,订单会直接录入到仓库管理软件中. 仓管在系统中可以一目了然的查询商品库存和订单需求数量.根据库存 ...

  10. TFS2012团队管理基本配置及基础使用方法

    本文介绍如何在VS2012中使用微软提供的TFS2012服务器进行团队协作开发,免费默认只支持5用户,主要分为两大步服务器配置跟客户端配置. 转载请标注:http://www.kwstu.com/Ar ...