应用程序之UITableView的编辑模式
- cell分层结构
- 效果展示
- 代码实现
一、cell的分层结构


二、效果展示


三、代码实现
//
// ViewController.m
// 01-TableView的删除实现
//
// Created by apple on 14-4-8.
// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
// #import "ViewController.h"
#import "Person.h" @interface ViewController () <UITabBarDelegate, UITableViewDataSource>
{
NSMutableArray *persons;
}
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; persons = [NSMutableArray array];
for (int i = ; i<; i++) {
Person *p = [Person personWithName:[NSString stringWithFormat:@"person--%d", i] phone:[NSString stringWithFormat:@"%d", + arc4random_uniform()]];
[persons addObject:p];
}
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return persons.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
} Person *person = persons[indexPath.row]; cell.textLabel.text = person.name;
cell.detailTextLabel.text = person.phone; return cell;
} #pragma mark -删除方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle != UITableViewCellEditingStyleDelete) return; [persons removeObjectAtIndex:indexPath.row]; [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
} #pragma mark -拖动方法
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
Person *p = persons[sourceIndexPath.row];
[persons removeObjectAtIndex:sourceIndexPath.row];
[persons insertObject:p atIndex:destinationIndexPath.row];
} - (IBAction)remove:(id)sender {
BOOL result = !_tableView.editing;
[_tableView setEditing:result animated:YES];
}
@end
应用程序之UITableView的编辑模式的更多相关文章
- 让UITableView进入编辑模式
1.UITableView对象有一个editing属性,设为YES时,该对象会进入编辑模式(editing mode).表格视图进入编辑模式后,用户可以管理表格中得行,如改变行的排列顺序.增加行或删除 ...
- UITableView的编辑模式
UITableView可以分普通模式和Editing模式两种,这里我们着重讨论Editing模式,Editing模式中又分三种操作:Insert.Delete. Reallocted.Insert和D ...
- Unreal开发HTC Vive程序,开启VR编辑模式
新建项目模板有个VirtualReality 调试的时候,Play按钮下拉有个VR Preview 打开VR模式,在我现在用的4.15.0版本,VR编辑模式还是预览功能,可以在“编辑器偏好设置”-“试 ...
- UITableView编辑模式大全解
1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...
- IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)
**********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...
- C#下控制台程序窗口下启用快速编辑模式运行线程会阻止线程运行
最近做一个小的功能,使用C#控制台程序开启一个线程进行无限循环没5秒处理一次程序,发现控制台窗口在开启快速编辑模式情况下,进行选择程序打印 出来的文字后发现线程不走了,将快速编辑模式去除后,线程就不会 ...
- UITableView 编辑模式(增加-删除-移动---自定义左滑 title)
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- UITableView编辑模式
UITableView有两种模式,普通模式和编辑模式.在编辑模式下可以对cell进行排序.删除.插入等等. 如何进入编辑模式 调用tableView的setEditing(editing: Bool, ...
- UITableView 编辑模式(增加-删除-移动---自定义左滑 title) xib cell
参考: http://www.open-open.com/lib/view/open1430008922468.html - (void)viewDidLoad { [super viewDidLo ...
随机推荐
- 15个变态的Google面试题以及答案
在当前经济形势不景气的情况下,谷歌招聘新员工是一件令人振奋的事,特别是对那些在当前金融风暴中渴望找到安全港的年轻经理们和软件开发商们来说是个好消息. 不过,也不要高兴太早,谷歌在招聘新员工时,更加青睐 ...
- 寻找web根目录
有时候,在利用一些命令执行漏洞时,可以以较高权限执行一些操作,但在我们想要上传shell的时候,却找不到网站根目录,下面是一些日常使用的寻找网站根目录的方法,记录下: 1.jsp 查看当前路径,在这个 ...
- element ui form表单清空规则
公司项目重构,经过商定使用element ui.在重构项目的时候发现一下element ui上很蛋疼的东西. 例如,这个form表单就是一个.趁着在高铁上没事,把想写的东西写一下. 先说一下eleme ...
- IDA 调试 Android
最近都在学一些反编译安卓相关的东西,其实网上有很多教程关于用 IDA 调试 Android 的过程,主要记录一下我遇到的坑 首先 Android手机要是root过的 还要注意的一点是apk中的 And ...
- Eclipse 无法查看第三方jar包文件源代码解决方法
1.打开第三方依赖包,源文件的快捷键:ctrl + mouseClick 2.由于我们下载的第三方jar 包,如Spring等相关的依赖包时,并没有附加下载相应的源文件,所以经常出现如图的这种问题. ...
- hdu 1423 最长上升递增子序列
#include <iostream> #include <cstdio> #include <cstring> using namespace std; ; in ...
- LOJ#2132. 「NOI2015」荷马史诗
$n \leq 100000$个数字,放进$k$叉树里,一个点只能放一个数,使所有数字乘以各自深度这个值之和最小的同时,最大深度的数字最小. 哈夫曼.这是我刚学OI那段时间看到的,感觉就是个很无聊的贪 ...
- ef code first transform,add ef power tools add-in,add tangible t4 editor for enhancement.
use ef power tools, as to .edmx file,right click at view, choose generate database from model, then ...
- 移动开发平台 apicloud、wex5
http://www.apicloud.com/deepengine http://www.wex5.com
- web项目中引入jquery easyui
jQuery easyui是一个基于jquery的用户界面插件集合,可以做出各种炫酷页面效果,大中型项目都可以使用些框架,非常好用,而且它有中文网,提供了大量的demo.下面我们看怎么将它引入到项目中 ...