利用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. [原]DbHelper-SQL数据库访问助手

    using System; using System.Data; using System.Data.SqlClient; namespace Whir.Software.Framework.Ulti ...

  2. 11、使用 WinAppDeployCmd 部署appx 包到 Windows10 Mobile上(更新)

    在 Windows10 Mobile开发工具里,微软没有提供 wp8 sdk 中 Application Deployment 一样的部署工具,参考 了一下  StackOverflow 论坛上的帖子 ...

  3. Windows Phone8 遇见的问题

    1.公司的无线路由可以自动分发ip地址,模拟器可以自动获取ip,进行连接.宿舍的无线路设置了DHCP 不能自动分发ip地址,模拟器连接不到ip,上不去网,我就去hyper-v 管理器里修改了静态mac ...

  4. 利用phpexcel把excel导入数据库和数据库导出excel实现

    <?php ); ini_set(,,,date(,date(,,,date(,,,date(,date(,,,date()     ->setCellValue();); $objPHP ...

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

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

  6. hdu 4165 dp

    可以用卡特兰数做 以下分析转自:http://www.cnblogs.com/kevinACMer/p/3724640.html?utm_source=tuicool 这道题之前自己做的时候并没有反应 ...

  7. Python开发的10个小贴士

    下面是十个Python中很有用的贴士和技巧.其中一些是初学这门语言常常会犯的错误. 注意:假设我们都用的是Python 3 1. 列表推导式 你有一个list:bag = [1, 2, 3, 4, 5 ...

  8. Android SQLite数据库版本升级原理解析

    Android使用SQLite数据库保存数据,那数据库版本升级是怎么回事呢,这里说一下. 一.软件v1.0 安装v1.0,假设v1.0版本只有一个account表,这时走继承SQLiteOpenHel ...

  9. html 绘制图像

  10. js:语言精髓笔记7----原型继承

    面向对象有三个基本特性:封装,继承,多态:如果都满足的话称为面向对象语言:而部分满足则称为基于对象语言: 数据类型实现模型描述: JavaScript对象模型: 构造过程:函数->构造器 构造器 ...