IOS基础18之UITableView--编辑模式:添加、删除、移动
| #pragma mark - 生命周期方法 |
| #pragma mark - 数据源方法 (其中有两个必要的方法) |
第一个方法:告诉这个tableView有多少行
| - (NSInteger)tableView :(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{} |
第二个方法:告诉某一行显示什么数据
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{} |
------------------------------------------------------------------------------------------------------------------------
| #pragma mark - 代理方法 |
| 1>>#pragma mark 设置每行的高度 |
| 2>>#pragma mark 提交编辑操作时会调用这个方法(删除、添加) |
---->删除操作
2.1.删除数据2.2.更新UITableView UI 界面 ---有两种方法,任选一种即可2.2.1> [tableView reloadData];//没有动画效果 2.2.2> [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];//有动画效果 |
---->添加操作
2.1.添加数据2.2.更新UI界面[tableView insertRowsAtIndexPaths.....] |
| 3>>#pargma mark 决定tableView的编辑模式 |
| UITableViewCellEditingStyle // 当前的编辑模式 |
| 4>>#pragma mark 只有实现这个方法,编辑模式中允许移动Cell |
| moveRowAtIndexPath:(NSIndexPath *)sourceIndexpath...... |
--------------------------------------------------------------------------------------------------
#pragma mark - 公共方法
#pragma mark 删除数据
1、开启编辑模式
self.tableViewl.editing = YES;//没有动画效果
[self.tableView setEditing:YES animated:YES];有动画效果
2、开户\关闭编辑模式
BOOL isEditing = self.tableView.isEditing;
[self.tableVeiw setEditing:!isEditing animated:YES];

浙公网安备 33010602011771号