:自定义Cell中的代码

#import <UIKit/UIKit.h>
@interface TestCell : UITableViewCell
@property(nonatomic,copy)NSString *content;
/**
* 标记行是否被选中
*/
@property(nonatomic,assign)BOOL isChecked;
@end
#import "TestCell.h"
@interface TestCell()
@property (weak, nonatomic) IBOutlet UIImageView *mark_ImageView;
@property (weak, nonatomic) IBOutlet UILabel *firstLabel; @end @implementation TestCell - (void)awakeFromNib
{
self.mark_ImageView.hidden = YES;
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; }
-(void)setContent:(NSString *)content
{
if (_content!=content) {
_firstLabel.text=content;
} }
/**
* 这里只是用到了一张图所以通过来imageview的hidden来显示是否选中
*
* @param isChecked
*/
- (void)setIsChecked:(BOOL)isChecked
{
_isChecked = isChecked;
//选中
if (_isChecked) {
self.mark_ImageView.hidden = NO;
self.mark_ImageView.image = [UIImage imageNamed:@"choice"];
}
else
{
self.mark_ImageView.hidden = YES;
} } @end :ViewController中的代码 #import "ViewController.h"
#import "TestCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate> @property(nonatomic,strong)NSMutableArray *dataArray; /**
* 保存选中行的对应的数据
*/
@property(nonatomic,strong)NSMutableArray *markArray; /**
* 保存标记选中行字典的数组
*/
@property(nonatomic,strong)NSMutableArray *checkArray; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; for (NSInteger i=; i<; i++) {
[self.dataArray addObject:[NSString stringWithFormat:@"选中第%ld行",i]];
} for (NSInteger i =; i<self.dataArray.count; i++) {
NSMutableDictionary *resultDict = [NSMutableDictionary dictionaryWithObject:@ forKey:@"isChecked"];
[self.markArray addObject:resultDict];
} } - (NSMutableArray *)dataArray{ if (!_dataArray) {
_dataArray =[NSMutableArray array];
}
return _dataArray; } - (NSMutableArray *)markArray{ if (!_markArray) {
_markArray =[NSMutableArray array];
}
return _markArray; } - (NSMutableArray *)checkArray{ if (!_checkArray) {
_checkArray =[NSMutableArray array];
}
return _checkArray; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
static NSString *cellIdentifier = @"TestCell";
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ TestCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
cell.content= self.dataArray[indexPath.row];
NSDictionary *resultDict = self.markArray[indexPath.row];
cell.isChecked = [resultDict[@"isChecked"] boolValue];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44.0f;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TestCell *cell = (TestCell *)[tableView cellForRowAtIndexPath:indexPath];
NSString *checkString = self.dataArray[indexPath.row];
NSMutableDictionary *checkedResult = self.markArray[indexPath.row];
//isChecked为NO则表明要把这行置为选中状态
if ([checkedResult[@"isChecked"] boolValue]==NO) {
[checkedResult setValue:@ forKey:@"isChecked"];
cell.isChecked = YES;
[self.checkArray addObject:checkString]; }
else{
[checkedResult setValue:@ forKey:@"isChecked"];
cell.isChecked = NO;
[self.checkArray removeObject:checkString]; }
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//刷新指定的行
NSIndexPath *indexPath_Row=[NSIndexPath indexPathForRow:indexPath.row inSection:];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath_Row,nil] withRowAnimation:UITableViewRowAnimationNone];
NSLog(@"self.checkArray =%@",self.checkArray); } @end

iOS - UITableView 多选功能实现的更多相关文章

  1. IOS UITableView多选删除功能

    UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,比如购物车.收藏列表等. 单行删除功能可以直接使用系统自带的删除功能,当横向轻扫cell时,右侧出现红色的删除按钮,点击删除 ...

  2. IOS UITableView拖动排序功能

    UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,排序等功能,下面就来讲解一下如何实现排序. 排序是当表格进入编辑状态后,在单元格的右侧会出现一个按钮,点击按钮,就可以拖动单 ...

  3. ios UITableView多选删除

    第一步, - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath ...

  4. IOS UITableView索引排序功能

    UITbableView分组展示信息时,有时在右侧会带索引,右侧的索引一般为分组的首字母,比如城市列表的展示.当点击右侧索引的字母,列表会快速跳到索引对应的分组,方便我们快速查找.下面,就介绍一下索引 ...

  5. iOS开发——UI_swift篇&UITableView实现索引功能

    UITableView实现索引功能     关于UItableView的索引在平时项目中所见不多,最多的就是跟联系人有关的界面,虽然如此,但是作为一个swift开发的程序必须知道的一个技术点,所以今天 ...

  6. iOS中的界面多选功能--(UICollectionView)

    文/Jacob_Pan(简书作者)原文链接:http://www.jianshu.com/p/9d28ebd0f5a2著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 最近做项目接触了一 ...

  7. iOS UITableView的多选

    一些列表经常需要编辑多选的功能,而UITableview自带多选删除的功能,使用起来方便,不需要自己去做数据存储和选中状态转换,可以减少不少开发时间.下面就来介绍下UITableView多选的使用. ...

  8. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

  9. UITableView多选删除

    设置一个在编辑状态下点击可改变图片的cell FileItemTableCell.h #import <UIKit/UIKit.h> @interface FileItemTableCel ...

随机推荐

  1. iframe 与frameset

    frameset 元素可定义一个框架集.它被用来组织多个窗口(框架).每个框架存有独立的文档.在其最简单的应用中,frameset 元素仅仅会规定在框架集中存在多少列或多少行.您必须使用 cols 或 ...

  2. BNUOJ 33898 Cannon

    Cannon Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged on HDU. Original ID: 449 ...

  3. Python学习笔记 (1)Hello World(环境搭建+输出Hello World!)

    随想 高考发挥失常.科三遇火车发挥失常,各种不顺……突然发现假期都快没了,才想起高考前想象的这个假期要做的一堆事,现在来多完成一件吧. 这几篇博客仅只是我的学习笔记,凑合看吧.我这个python小白看 ...

  4. noip模拟赛 排列

    [问题描述] 给出一个随机的排列,请你计算最大值减最小值的差小于等于0~n-1的区间分别有多少个. 输入格式 输入文件名为sum.in. 第一行一个数T(<=10),表示数据组数 对于每一组数据 ...

  5. poj 2823单调队列模板题

    #include<stdio.h>//每次要吧生命值长的加入,吧生命用光的舍弃 #define N  1100000 int getmin[N],getmax[N],num[N],n,k, ...

  6. Win32编程API 基础篇 -- 4.消息循环

    消息循环 理解消息循环 为了编写任何即使是最简单的程序,了解windows程序的消息循环和整个消息发送结构是非常有必要的.既然我们已经尝试了一点消息处理的东西,我们应该对整个程序有更深入的理解,如果你 ...

  7. alpha版出炉,实现win2008 service的session 0穿透

    指定用户名,拿最小session,实现和用户ui交互. 这样,搞windows的自动化部署,就可以向前一大步啦. 比以前用psexec要用户名密码,指定session要先进多啦. 安全保密性也提高了. ...

  8. kendo grid 点击更新没有反映

    因为没有在dataSource上写schema schema: { model: { id: "DeptId", fields: { CompanyId: { editable: ...

  9. Hackerrank alien-flowers(数学公式)

    题意:求能够构造出的符合以下条件的字符串的数目 .字符串只由R和B组成且长度不为0 .字符串含有A个RR,B个RB,C个BB,D个BR A,B,C,D<=1e5 分析:最简单的方法就是dp,但是 ...

  10. golang 中timer,ticker 的使用

    写一个程序, 5s, 10s后能定时执行一个任务,同时能不停的处理来的消息. ------------------------------------------------------------- ...