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 ...
随机推荐
- yum_rpm(利用dvd建立本地yum库)
#wget "http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os" 建立起了index.html ...
- SQL with as
姓名 课程 分数 张三 语文 张三 数学 张三 物理 李四 语文 李四 数学 李四 物理 先看下面一个嵌套的查询语句 ) 上面的查询语句使用了一个子查询.虽然这条SQL语句并不复杂,但如果嵌套的层次过 ...
- php 的函数参数值类型限定
如例: function test(array $a,test $b){ /*...*/ } class test{ /*...*/ } test(array(),new test); 表示test函 ...
- Xamarin.Android开发实践(九)
Xamarin.Android之ActionBar与菜单 一.选项卡 如今很多应用都会使用碎片以便在同一个活动中能够显示多个不同的视图.在 Android 3.0 以上的版本中,我们已经可以使用Act ...
- Android---让你的APK程序开机自动运行(转)
转自: http://blog.sina.com.cn/s/blog_72f6e45701014l6t.html 有些时候,应用需要在开机时就自动运行,例如某个自动从网上更新内容的后台service. ...
- [MySQL]导入导出
[MySQL]导入导出 一 导入文本数据 1)mysql->load data infile 数据文件c:/mytable.txt 如下:(每一行为一条记录,记录的字段间用tab隔开,最后一个字 ...
- DOS常用的简单命令
在windows下的cmd里使用 dir 列出当前目录下的文件及文件夹 md 创建目录 rd 删除目录(只能删除空目录) cd 进入指定目录 cd .. 返回上一级目录 cd / 返回到根目录 del ...
- Spring的循环依赖问题
spring容器循环依赖包括构造器循环依赖和setter循环依赖,那Spring容器如何解决循环依赖呢?首先让我们来定义循环引用类: 在Spring中将循环依赖的处理分成了3种情况: 构造器循环依赖 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- Play on Words[HDU1116]
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...