//  AppDelegate.m
// UI3_UITableViewDelete(多选)
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible]; return YES;
}
//
// ViewController.h
// UI3_UITableViewDelete(多选)
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @end //
// ViewController.m
// UI3_UITableViewDelete(多选)
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
{
UITableView *_tableView;
//数据源
NSMutableArray *_dataList;
//要删除的数据
NSMutableArray *_removeList;
} @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self creatDataSource];
[self creatUI];
} //创建数据源
- (void)creatDataSource
{
_dataList = [NSMutableArray array];
_removeList = [NSMutableArray array];
NSMutableArray *boys = [NSMutableArray array];
for (int i=0; i<20; i++) {
NSString *name = [NSString stringWithFormat:@"boy:%d", i+1];
[boys addObject:name];
}
[_dataList addObject:boys]; NSMutableArray *grils = [NSMutableArray array];
for (int i= 0; i<10; i++) {
NSString *name = [NSString stringWithFormat:@"gril:%d", i+1];
[grils addObject:name];
}
[_dataList addObject:grils];
} //创建UI - (void)creatUI
{
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; //设置代理
_tableView.delegate = self;
_tableView.dataSource = self; //设置尾视图
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 44)];
footerView.backgroundColor = [UIColor cyanColor];
_tableView.tableFooterView = footerView;
NSLog(@"view = %@", _tableView.tableFooterView);
//设置头视图
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, 44)];
headerView.backgroundColor = [UIColor yellowColor];
_tableView.tableHeaderView = headerView; //添加Btn UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame =CGRectMake(50, 0, footerView.frame.size.width-100,44);
[btn setTitle:@"remove" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(removeData) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:btn]; //设置编辑按钮
self.navigationItem.leftBarButtonItem = self.editButtonItem; [self.view addSubview:_tableView]; } //进入编辑状态 - (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:YES];
[_tableView setEditing:editing animated:YES];
} //Editing - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
//同时设置insert 及 delete 自动进入多选状态
return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
} //删除数据
- (void)removeData
{
for (int i=0; i<2; i++) {
NSArray *array = [[_dataList objectAtIndex:i] copy];
NSInteger rows = array.count;
for (int j=0; j<rows; j++) {
NSString *obj = [array objectAtIndex:j];
if ([_removeList containsObject:obj]) {
[[_dataList objectAtIndex:i] removeObject:obj];
}
}
}
[_tableView reloadData];
} #pragma mark ---UITableView--- //返回分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return _dataList.count;
} //返回每个分区有多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_dataList objectAtIndex:section] count];
} //返回UITableViewCell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [[_dataList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
return cell;
} //选中状态
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ if (tableView.editing) {
NSString *obj = [[_dataList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
if (![_removeList containsObject: obj])
{
[_removeList addObject:obj];
}
}
} //结束选中状态
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.editing) {
NSString *obj = [[_dataList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
if ([_removeList containsObject:obj]) {
[_removeList removeObject:obj];
}
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI3_UITableViewDelete(多选)的更多相关文章

  1. .net点选验证码实现思路分享

    哈哈好久没冒泡了,最进看见点选验证码有点意思,所以想自己写一个. 先上效果图 如果你被这个效果吸引了就请继续看下去. 贴代码前先说点思路: 1.要有一个汉字库,并按字形分类.(我在数据库里是安部首分类 ...

  2. Jquery的点击事件,三句代码完成全选事件

    先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  3. React使用antd Table生成层级多选组件

    一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...

  4. 关于 devbridge-autocomplete 插件多选操作的实现方法

    目前据我所知最好用的 autocomplete 插件就是 jquery-ui 的 autocomplete 以及 devbridge 的 autocomplete 插件. 我最终选择了 devbrid ...

  5. 企业做数据缓存是使用Memcached还是选Redis?

    企业是使用Memcached还是选Redis? 在构建一款现代且由数据库驱动的Web应用程序并希望使其拥有更为出色的性能表现时,这个问题总会时不时出现.并给每一位开发人员带来困扰.在考虑对应用程序的性 ...

  6. css3更改input单选和多选的样式

    在项目开发中我们经常会遇到需要更改input单选和多选样式的情况,今天就给大家介绍一种简单改变input单选和多选样式的办法. 在这之前先简单介绍一下:before伪类 :before 选择器向选定的 ...

  7. jquery实现下拉框多选

    一.说明 本文是利用EasyUI实现下拉框多选功能,在ComboxTree其原有的基础上对样式进行了改进,样式表已上传demo,代码如下 二.代码 <!DOCTYPE html PUBLIC & ...

  8. jquery.multiselect 多选下拉框实现

    第一步:链接下列文件,如果没有,到此网页下载 https://github.com/ehynds/jquery-ui-multiselect-widget,此插件基于jquery ,所以jquery的 ...

  9. 前端如何正确选择offer,到底选哪个?

    文章背景:来自于一次线上交流,当时回答感觉比较粗糙,做个阶段性的总结,也分享给其它朋友. 当时的题目是,共2个offer,如何选择: 1. 美团外卖前端 2. 京东深圳前端研发(只有通过邮件,还有收到 ...

随机推荐

  1. ecmall二次开发 直接实例化mysql对象

    $db = &db(); // 第一步赋值数据库类库, $db->query(sql); // 第二步执行mysql 语句; 常用的数据库函数: 得到一行数据 $user=$db-> ...

  2. 深刻理解Java中final的作用(一):从final的作用剖析String被设计成不可变类的深层原因

    声明:本博客为原创博客,未经同意,不得转载!小伙伴们假设是在别的地方看到的话,建议还是来csdn上看吧(原文链接为http://blog.csdn.net/bettarwang/article/det ...

  3. [终极精简版][图解]Nginx搭建flv mp4流媒体服务器

    花了我接近3周,历经了重重问题,今日终于把流媒体服务器搞定,赶紧的写个博文以免忘记... 起初是跟着网上的一些教程来的,但是说的很不全面,一些东西也过时不用了(比如jwplayer老版本).我这次是用 ...

  4. unity3d快捷键大全

    Unity是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面 整合的专业游戏引擎.Unit ...

  5. iOS开发——多线程OC篇&多线程详解

    多线程详解 前面介绍了多线程的各种方式及其使用,这里补一点关于多线程的概念及相关技巧与使用,相信前面不懂的地方看了这里之后你就对多线程基本上没有什么问题了! 1——首先ios开发多线程中必须了解的概念 ...

  6. C# Socket基础(一)之启动异步服务监听

    本文主要是以代码为主..NET技术交流群 199281001 .欢迎加入. //通知一个或多个正在等待的线程已发生事件. ManualResetEvent manager = new ManualRe ...

  7. js代码的一些小技巧

    1. 数组中通过赋值语句来改变值 var a = 1; var msg = ["value0","value1"]; for(var i = 0;i<10 ...

  8. Face The Right Way 一道不错的尺取法和标记法题目。 poj 3276

    Face The Right Way Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2899   Accepted: 133 ...

  9. org.apache.solr.common.util.ContentStream.java及其实现类

    org.apache.solr.common.util.ContentStream.java 主要是获取文件,URL,字节数组,字符串等的数据流.主要方法又InputStream getStream( ...

  10. Phong光照以及其他

        在说光照之前,有必要先弄清法线的变换,假设Mworld 将物体的定点一一变换到世界空间,如果我们对法线实施同样的变化,,以为能将法线变换到世界空间,但世界上变换之后的法线不再与表面垂直,就像下 ...