先看下效果图

直接上代码

#import "MyController.h"

@interface MyController ()
{
UIButton *button;
} @property(nonatomic,strong)NSMutableArray *array;//数据源 @property (nonatomic,strong)NSMutableArray *selectorPatnArray;//存放选中数据 @end @implementation MyController - (void)viewDidLoad {
[super viewDidLoad]; //添加数据源
for (int i = ; i < ; i++) {
NSString *str = [NSString stringWithFormat:@"第%d行",i + ];
[self.array addObject:str];
} button = [UIButton buttonWithType:(UIButtonTypeCustom)];
[button setTitle:@"选择" forState:(UIControlStateNormal)];
[button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
button.frame = CGRectMake(, , , ); [button addTarget:self action:@selector(selectMore:) forControlEvents:(UIControlEventTouchUpInside)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.array.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Identifier = @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
}
cell.textLabel.text = self.array[indexPath.row];    cell的selectionStyle不要设置为UITableViewSelectionStyleNone return cell;
} - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{ return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//选中数据
[self.selectorPatnArray addObject:self.array[indexPath.row]]; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
//从选中中取消
if (self.selectorPatnArray.count > ) { [self.selectorPatnArray removeObject:self.array[indexPath.row]];
} } #pragma mark - 点击事件 - (void)selectMore:(UIBarButtonItem *)action{
if ([button.titleLabel.text isEqualToString:@"选择"]) {
//移除之前选中的内容
if (self.selectorPatnArray.count > ) {
[self.selectorPatnArray removeAllObjects];
}
[button setTitle:@"确认" forState:(UIControlStateNormal)];
//进入编辑状态
[self.tableView setEditing:YES animated:YES];
}else{ [button setTitle:@"选择" forState:(UIControlStateNormal)];
     //对选中内容进行操作
NSLog(@"选中个数是 : %lu 内容为 : %@",(unsigned long)self.selectorPatnArray.count,self.selectorPatnArray);
//取消编辑状态
[self.tableView setEditing:NO animated:YES]; }
} #pragma mark -懒加载 -(NSMutableArray *)array{
if (!_array) {
_array = [NSMutableArray array];
}
return _array;
} - (NSMutableArray *)selectorPatnArray{
if (!_selectorPatnArray) {
_selectorPatnArray = [NSMutableArray array];
}
return _selectorPatnArray;
}

如果要把tableView在非编辑状态下不让点击,设置下这个属性,就OK了.

@property (nonatomic) BOOL allowsSelection NS_AVAILABLE_IOS(3_0);  // default is YES. Controls whether rows can be selected when not in editing mode

如果在某些情况下需要全选,可以按照这个思路:

        for (int i = ; i < self.array.count; i++) {
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:];
UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:path];
cell.selected = YES;
[self.selectorPatnArray addObject:self.array[i]];//添加到选中列表 }

这只是个人想法,欢迎指出不足......

iOS开发UI篇-tableView在编辑状态下的批量操作(多选)的更多相关文章

  1. iOS开发UI篇—UITableview控件基本使用

    iOS开发UI篇—UITableview控件基本使用 一.一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) #import <Foundation/Foundation.h> ...

  2. iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建

    iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建 一.实现效果 说明:该示例在storyboard中使用动态单元格来完成. 二.实现 1.项目文件结构 ...

  3. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  4. iOS开发UI篇—核心动画(关键帧动画)

    转自:http://www.cnblogs.com/wendingding/p/3801330.html iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimatio ...

  5. iOS开发UI篇—核心动画(基础动画)

    转自:http://www.cnblogs.com/wendingding/p/3801157.html 文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(基础动画) iOS ...

  6. iOS开发UI篇—核心动画简介

    转自:http://www.cnblogs.com/wendingding/p/3801036.html iOS开发UI篇—核心动画简介 一.简单介绍 Core Animation,中文翻译为核心动画 ...

  7. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  8. iOS开发UI篇—Quartz2D使用(绘制基本图形)

    iOS开发UI篇—Quartz2D使用(绘制基本图形) 一.简单说明 图形上下文(Graphics Context):是一个CGContextRef类型的数据 图形上下文的作用:保存绘图信息.绘图状态 ...

  9. iOS开发UI篇—Button基础

    iOS开发UI篇—Button基础 一.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 二.按钮的三种状 ...

随机推荐

  1. CentOS5.5 下编译安装 LAMP

    大纲 1.安装gcc编译器 2.卸载rpm安装的http和mysql软件 3.编译安装php依赖包 4.安装apache软件 5.安装mysql软件 6.安装php软件 7.安装memcache ph ...

  2. Dom4j的使用(全而好的文章)

        版权声明: 本文由冰云完成,首发于CSDN,未经许可,不得使用于任何商业用途. 文中代码部分引用自DOM4J文档. 欢迎转载,但请保持文章及版权声明完整. 如需联络请发邮件:icecloud( ...

  3. [light oj 1013] Love Calculator

    1013 - Love Calculator Yes, you are developing a 'Love calculator'. The software would be quite comp ...

  4. GIS数据格式:Shapefile

    转自:http://lab.osgeo.cn/2449.html Shapefile是ESRI提出的数据格式,随着ArcView GIS 3.x发布,属于简单要素类.Shapefile由于其数据结构简 ...

  5. HDU5649 DZY Loves Sorting 线段树

    题意:BC 76 div1 1004 有中文题面 然后奉上官方题解: 这是一道良心的基础数据结构题. 我们二分a[k]的值,假设当前是mid,然后把大于mid的数字标为1,不大于mid的数字标为0.然 ...

  6. Ruby require 路径问题

    require 负责引用一个外部文件,可以省略".rb"字样. 如: require 'foo.bar' 等价于 require 'foo' 在Ruby中,同一目录下的文件, 如 ...

  7. [POJ1852]Ants

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12431   Accepted: 5462 Description An a ...

  8. shell常用命令总结

    统计文件行数 wc -l filename grep -c "" filename sed -n '$=' filename awk 'END{print NR}' filenam ...

  9. POJ-3648 Wedding 2sat

    题目链接:http://poj.org/problem?id=3648‘ 题意:一对情人举行婚礼,有n对夫妇参加,别人对着坐在一个长桌子的两边,新娘和新郎坐在最后面,新娘只能看见坐在他对面的人.现在, ...

  10. Nginx+Lua+Redis整合实现高性能API接口 - 网站服务器 - LinuxTone | 运维专家网论坛 - 最棒的Linux运维与开源架构技术交流社区! - Powered by Discuz!

    Nginx+Lua+Redis整合实现高性能API接口 - 网站服务器 - LinuxTone | 运维专家网论坛 - 最棒的Linux运维与开源架构技术交流社区! - Powered by Disc ...