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 ...
随机推荐
- 如何 ︰ 执行批量更新和插入使用.NET 提供程序在 C#.NET OpenXML
https://support.microsoft.com/zh-cn/kb/315968 如何 ︰ 执行批量更新和插入使用.NET 提供程序在 C#.NET OpenXML Email Prin ...
- phpstorm取消自动保存并标识修改的文件为星星标记
PhpStorm是一个轻量级且便捷的PHP IDE,其旨在提供用户效率,可深刻理解用户的编码,提供智能代码补全,快速导航以及即时错误检查. 自从使用上了phpstrom后就放弃了zendstudio, ...
- Java Hour 36 Weathre ( 9 ) struts2 – exception
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 35 Exception Handling 直接添加全局性的异常处理 ...
- AppInventor学习笔记(五)——瓢虫快跑应用学习
一.瓢虫引入 1:加入控件: 先引入方框中含有的控件,里面有两个画布,一个图像精灵,一个重力感应,一个时钟(设为10Ms).顺手改名.设置图像精灵的移动speed为10,并且引入瓢虫的图像 2.加入逻 ...
- hadoop系列讨论
生产环境下cloudera的cdh版本更受欢迎,但是貌似cloudera对于YARN的开发力度不是很突出,所以在apache与cdh版本选择的时候,大家是怎么考虑的? 主要关注生产环境下的运维成本,期 ...
- C# 中Datetime类用法总结
收集了一些记录下来,这些有的是从网上找的,有些是自己使用到的: DateTime dt = DateTime.Now; dt.ToString();//2005-11-5 13:21:25dt.ToF ...
- Android SeekBar自定义使用图片和颜色显示
案例使用的图片如下: 1.在res/drawable目录下新增一个xml风格文件,seekbar_define_style.xml ? 1 2 3 ...
- loadrunner中定义数组
loadrunner 中数组的定义 loadrunner 中数组的定义: lr_save_string("www.google.com","website_1" ...
- Swift语言中为外部参数设置默认值可变参数常量参数变量参数输入输出参数
Swift语言中为外部参数设置默认值可变参数常量参数变量参数输入输出参数 7.4.4 为外部参数设置默认值 开发者也可以对外部参数设置默认值.这时,调用的时候,也可以省略参数传递本文选自Swift1 ...
- html加强
<html> <head><title>hello</title></head> <body> <p>段落</ ...