UIday1001:UITableView 2 编辑(添加、删除)、移动、UITableViewController

来源:互联网 发布:手机虚拟机安装windows 编辑:程序博客网 时间:2024/06/05 06:20
一、 tableView 编辑
 tableView 的编辑:cell的添加、删除。
 使⽤用场景:
 删除⼀个下载好的视频,删除联系⼈;
 插⼊一条新的聊天记录等
 1、让tableView处于编辑状态
 - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
 2、指定tableView哪些⾏可以编辑
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
 3、指定tableView编辑的样式(添加、删除)
 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
 4、编辑完成(先操作数据源,再修改UI)
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
 
 
 ⼆、 tableView 移动
 1、让tableView处于编辑状态
 - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
 2、指定tableView哪些行可以移动
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
 3、移动完成
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
 监测移动过程,实现限制跨区移动
 - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;
 
 
 
 三、 UITableViewController
 UITableViewController继承⾃UIViewController,⾃带⼀个tableView
 self.view不是UIView而是UITableView
 datasource和delegate 默认都是self(UITableViewController)
 开发中只需要建立 UITableViewController ⼦类
 
 ⽆论编辑还是移动,都先让 tableView 进⼊编辑状态。 编辑结束或者移动结束, 要先修改数组或字典中的数据,再更改UI。
 UITableViewController 是封装好了各种 delegate 和 datasource ,能提⾼我们开发速度。
0 0
原创粉丝点击