UITableview cell 的多选
利用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 的多选的更多相关文章
- UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题
UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...
- Why does uitableview cell remain highlighted?
What would cause a tableview cell to remain highlighted after being touched? I click the cell and ca ...
- UITableView cell中label自动换行和自定义label自动换行
换行的前提必须是有足够的高度 才能换 否则不显示超出部分 所以,在设置label换行的时候 要考虑cell的高度,cell的高度也要变化,废话不多说,来段代码: cell.label.text=[di ...
- UITableView Cell 弹簧动画效果
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...
- Swift - UIView,UItableView,Cell设置边框方法
// 设置边框的宽度 cell.layer.borderWidth = 1 // 设置边框的颜色 cell.layer.borderColor = UIColor.blackColor().CGCol ...
- UITableview cell中多个按钮
xib的 //不使用这种- (IBAction)button:(UIButton *)sender; //使用这种 @property (weak, nonatomic) IBOutlet UIBut ...
- UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法
如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...
- 【iOS】UITableview cell 顶部空白的n种设置方法
我知道没人会主动设置这个东西,但是大家一定都遇到过这个问题,下面总结下可能是哪些情况: 1, self.automaticallyAdjustsScrollViewInsets = NO; 这个应该 ...
- 设置cell背景色和选中色
// 设置cell的背景色 UIView *bg = [[[UIView alloc] init] autorelease]; bg.backgroundColor = [UIColor colorW ...
随机推荐
- js event 事件兼容浏览器 ie不需要 event参数 firefox 需要
js event 事件兼容浏览器 ie不需要 event参数 firefox 需要 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- Android Bitmap详细介绍
package com.testbitmapscale; import java.io.File; import java.io.FileInputStream; import java.io.Fil ...
- 关于LR中的EXTRARES
LoadRunner脚本之EXTRARES参数 EXTRARES:分隔符,表示标记下一个属性是资源属性的列表(list of resource attributes). [EXTRARES后的资源是由 ...
- .Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");
今天就说说.Net中通过反射取得某个类型时,我们怎么知道这个类型在硬盘上的哪个角落?比如说,假如我们需要要求服务端动态载入某个数据源,那服务端怎么知道数据源在哪?网上大部分的教程都写着,可以使用Ass ...
- SU Demos-03T-F Analysis-02Sutvband
第一个脚本,生成震源扫描信号,并进行gabor变换 运行结果, 第二个脚本,利用时变滤波从和信号中重建单独的3个扫描信号 运行结果
- logback 配置详解【讲解较全的博客网站】
http://blog.csdn.net/haidage/article/category/812478 详解(一)http://blog.csdn.net/haidage/article/detai ...
- 使用Javascript无限添加QQ好友原理解析
做QQ营销的朋友都知道,QQ加好友是有诸多限制的,IP限制,次数限制,二维码限制,人数限制,使用软件自动加好友会遇到各种各样的问题,很多软件通过模拟人工添加QQ号码,在添加几个之后就会遇到腾讯规则限制 ...
- ZOJ3228 Searching the String(AC自动机)
题目大概是给一个主串,询问若干个模式串出现次数,其中有些模式串要求不能重叠. 对于可以重叠的就是一个直白的多模式匹配问题:而不可重叠,在匹配过程中贪心地记录当前匹配的主串位置,然后每当出现一个新匹配根 ...
- Comparing the Performance of .NET Serializers(zz)
The .NET framework comes with a variety of different serializers. Hopefully, my overview of these se ...
- WebRTC手记Channel概念
转载请注明出处:http://www.cnblogs.com/fangkm/p/4401075.html 前面两篇博文完整地介绍了WebRTC音视频的采集模块,接下来应该开始介绍关键的音视频编码模块. ...