ios 简单实现tableView单选和多选功能
来源:互联网 发布:淘宝怎么同城购物图解 编辑:程序博客网 时间:2024/04/30 07:45
代码如下:
#import "ViewController.h"@interface ViewController ()<UITableViewDataSource,UITableViewDelegate> { NSInteger index; BOOL isRadio;}@property (weak, nonatomic) IBOutlet UITableView *tableView;@property(nonatomic,strong)NSMutableArray *datas;@property(nonatomic,strong)NSMutableDictionary *mDic;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.datas = [NSMutableArray array]; self.mDic = [NSMutableDictionary dictionary]; for (int i=0; i<100; i++) { [self.datas addObject:[NSString stringWithFormat:@"cell%d",i]]; [self.mDic setObject:@0 forKey:@(i)]; } [self.tableView reloadData];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.datas.count;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = self.datas[indexPath.row]; if (isRadio) { if (indexPath.row == index) { cell.textLabel.textColor = [UIColor redColor]; }else { cell.textLabel.textColor = [UIColor blackColor]; } }else { if ([[self.mDic objectForKey:@(indexPath.row)] intValue]) { cell.textLabel.textColor = [UIColor redColor]; }else { cell.textLabel.textColor = [UIColor blackColor]; } } return cell;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { index = indexPath.row; [self.mDic setObject:@1 forKey:@(indexPath.row)]; [tableView reloadData];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- ios 简单实现tableView单选和多选功能
- iOS中tableview实现单选和多选
- iOS开发tableView实现单选和复选
- iOS开发tableView实现单选和复选
- ios tableview单选
- iOS tableview 实现简单的搜索功能
- iOS tableview 实现简单的搜索功能
- iOS tableview 实现简单的搜索功能
- iOS UISearchController TableView 实现简单搜索功能
- iOS学习笔记-- tableView单选的实现
- Listview实现简单的单选功能
- IOS开发之tableview单选
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS学习笔记--tableView多选实现
- iOS tableView卷展 多选及全选功能
- 实现tableView多选功能及出现问题解决
- 实现tableView多选功能及出现问题解决
- 几位成功投资者最珍视的理财箴言
- js拼接字符串时转义字符的妙用
- SSL握手通信详解及linux下c/c++ SSL Socket(另附SSL双向认证客户端代码)
- 防盗链——防止其他页面通过url直接访问本站资源
- canvas绘图基础(五)
- ios 简单实现tableView单选和多选功能
- 二维数组应用举例:游戏“一担挑”(tic-tac-toe)
- java连接hbase
- win10与linux双系统
- 逻辑运算与位运算区别
- 数百种编程语言,我为什么只学Python?
- 干货|智能时代下,下一波产品红利在哪里?
- ubuntu install vlc [译]
- 细说equals()方法和hashCode()方法