利用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. Animation & Property Animation 使用

    本篇主要讲Animation 和 Property Animation的使用,最后会讲QQ管家桌面火箭作为例子: 在Android中开发动效有两套框架可以使用,分别为 Animation 和 Prop ...

  2. php封装练习

    <body> <?php class jisuan { private $a; private $b; function __construct($a,$b) { $this-> ...

  3. JS输入框邮箱自动提示(带有demo和源码)(转载)

    今天在javascriptQQ群里面 有童鞋问到 有没有 "JS输入框邮箱自动提示"插件,即说都找遍了github上源码 都没有看到这样类似的插件,然后我想了下 "JS输 ...

  4. Jil序列化JSON

    使用Jil序列化JSON提升Asp.net web api 性能   JSON序列化无疑是Asp.net web api 里面性能提升最重要的一环. 在Asp.net web api 里面我们可以插入 ...

  5. [原]FileHelper-文件操作辅助类

    using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Whir.S ...

  6. 关于Android开发中的证书和密钥等问题

    关于Android开发中的证书和密钥等问题 引言 除了Android发布应用签名时需要用到证书外,在进行google Map Api开发和Facebook SDK API开发等时都需要申请API Ke ...

  7. SQL SERVER 与ACCESS、EXCEL的数据转换

    --Excel导入到SQL的一个新思路: /*比如Excel有两列,A列和B列需要导入到SQL表中,反正我已经有几年不用DTS之类的工具了. 在Excel中的新的一列中,直接写公式 =CONCATEN ...

  8. VMware安装、配置CentOS

    出处:http://www.cnblogs.com/jlily/ 1. 准备CentOS安装镜像文件 官网下载地址:http://www.centos.org/download/ 官方有三个版本:DV ...

  9. 【JUnit 报错】java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/Message

    使用JUnit的时候,报错:java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/Message 原因是因为项目中导入的架包 ...

  10. Linux常用命令_(文件搜索)

    文件查找主要包含以下几个命令 which.whereis.grep.find.wc