应用程序之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 ...
随机推荐
- How to modify a compiled Android application (.apk file)
Today I’d like to share with you my findings about how an existing .apk file can be modified. An .ap ...
- Canvas与Image互相转换示例以及利用该技术实现微信长按自动识别二维码功能
现在扫描二维码已经很普遍,微信扫一扫即可,但是如果二维码是在自己的手机上呢?那就要用到微信里的一个功能了,手指长按二维码,会弹出自动识别的选项,点确定就可以看到二维码的内容了.那么怎么通过前端实现这个 ...
- BZOJ1566 [NOI2009]管道取珠 【dp】
题目 输入格式 第一行包含两个整数n, m,分别表示上下两个管道中球的数目. 第二行为一个AB字符串,长度为n,表示上管道中从左到右球的类型.其中A表示浅色球,B表示深色球. 第三行为一个AB字符串, ...
- 编码风格——linux内核开发的coding style
总结linux内核开发的coding style, 便于以后写代码时参考. 下面只是罗列一些规则, 具体说明可以参考: 内核源码(Documentation/CodingStyle) 01 - 缩进 ...
- SQLServer (2005/2008) 日志清理方法
--数据库日志名称查询 USE DBNAME GO SELECT file_id, name,* FROM sys.database_files; GO------------------------ ...
- [ARC082F] Sandglass(线段树)
Description 有一个沙漏由两个上下相通玻璃球 \(A\) 和 \(B\) 构成,这两个玻璃球都含有一定量的沙子,我们暂且假定 \(AB\) 中位于上方的玻璃球的为 \(U\),下方的玻璃球为 ...
- gridview行链接
原文发布时间为:2009-04-21 -- 来源于本人的百度文章 [由搬家工具导入] 点击行,链接!! 可这样,在GridView的RowDataBound输入代码,假如id在第0列,且不是摸板列: ...
- sql语句中的[]中括号(转)
下面有关sql语句中[]的信息适用于Sql Server.Access等多种数据库. 1.sql语句中加[]是为了防止歧义,避免与系统保留关键字冲突,使计算机能识别.sql语句中有些字段可能是关键字, ...
- Hotspot JVM下,parallel与concurrent的区别
转载于知乎 作者:Ted Mosby链接:https://www.zhihu.com/question/21535747/answer/144884632来源:知乎著作权归作者所有.商业转载请联系作者 ...
- sprintf 心得
[string print format]sprintf指的是字符串格式化命令. [主要功能]是把格式化的数据写入某个字符串中. sprintf是个变参函数. 使用sprintf对于写入buffer的 ...