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 ...
随机推荐
- unix/linux进程详解——代码
#include <iostream>#include <vector>#include <cstdint>#include <cstring>#inc ...
- 微信api退款操作
状况:证书加载进去,本地调试退款成功,然而发不到iis上却是不成功. 分析:定然是iis配置问题. 问题一:证书加载不进去,出现“内部错误” 解决:在iis中找到对应的应用连接池,右键高级设置,找到“ ...
- django默认开事务的麻烦事
最近DBA发现总是有大事务报警,最终排查到是因为django默认在查询之前执行了 set autocommit=0 原来,mysql如果开了set autocommit=0,那么所有的语句一定是在一个 ...
- Java Hour 23 Networking
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 首先拟好主题,做到心中有数,再去写内容. socket public stat ...
- wp8 --未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出
今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目,但是并没有像之前那样顺利的创建页面,而是弹出了一个错误窗口. 我的系统是win8专业版 64位 ,同时 ...
- hdu 2191 完全背包
为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买.请问:你用有限的资金最多能采购多少 ...
- 个人电脑配置FTP服务器,四张图搞定。项目需要,并自己写了个客户端实现下载和上传的功能!
测试结果:
- Windows计数器做性能监控(window server 2008服务器)
使用Windows计数器 一.创建数据收集器集 二.创建数据收集器 三.使用数据收集器 1.修改数据收集器的属性 2.手动启用.手动停止数据收集器集 3.计划任务 4.在性能监视器中查看 一.性能监视 ...
- JVM的生命周期
package test; public class JVMTestLife { public static void main(String[] args) { new Thread(new Run ...
- Ajax 学习之获取服务器的值
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...