IOS开发笔记-UITableView的多选
2015-11-26 09:19
302 查看
//
// JPViewController.m
// MultiSelectDemo
//
// Created by kuaitu on 15/1/9.
// Copyright (c) 2015年JP. All rights reserved.
//
#import "JPViewController.h"
@interface JPViewController ()
@end
@implementation JPViewController
{
int _row;
int _rowNum;
BOOL _selected[20];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
#pragma mark - UITableViewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];
}
cell.tintColor = [UIColorredColor];
if (_selected[indexPath.row]) {
cell.accessoryType =UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType =UITableViewCellAccessoryNone;
}
cell.textLabel.text =@"111";
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selected[indexPath.row] = !_selected[indexPath.row];
[tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// JPViewController.m
// MultiSelectDemo
//
// Created by kuaitu on 15/1/9.
// Copyright (c) 2015年JP. All rights reserved.
//
#import "JPViewController.h"
@interface JPViewController ()
@end
@implementation JPViewController
{
int _row;
int _rowNum;
BOOL _selected[20];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
#pragma mark - UITableViewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];
}
cell.tintColor = [UIColorredColor];
if (_selected[indexPath.row]) {
cell.accessoryType =UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType =UITableViewCellAccessoryNone;
}
cell.textLabel.text =@"111";
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selected[indexPath.row] = !_selected[indexPath.row];
[tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- JS实现支持多选的遍历下拉列表代码
- 利用Jquery实现可多选的下拉框
- 两个select多选模式的选项相互移动(示例代码)
- Jquery多选下拉列表插件jquery multiselect功能介绍及使用
- 使用Java获取html中Select,radio多选的值方法
- 基于javascript实现单选及多选的向右和向左移动实例
- UITableView 实现汽车品牌(demo)
- IOS 9 UITableView整理
- UITableView 基本使用方法总结
- UITableView一些易混属性和方法
- UITableView的详细讲解
- (转)UITableViewController重要配置方法和Delegate
- UITableView详细用法,UITableView指南,UITableView详细教程
- ios隐藏uitableview下面多余的tableview的线条
- 定制UITableViewCell的事件响应处理
- ios关于tableView的重用
- UITableView Plain下的section取消顶部粘连
- IOS UITableView 实现LOL数据展示
- iOS开发之UITableView多选
- iOS- UITableView