简单介绍一下UITableView删除移动单元格实现的步骤:
1、头文件添加代理UITableViewDataSource,.m文件设置代理添加表视图到self.view
_tableView.delegate = self; _tableView.dataSource = self; [self.view addSubview:_tableView];
2、完成UITableViewDataSource两个必须实现的代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
3、现在如果能够正常显示数据那么继续下面的步骤
4、(特性1)在下面这个函数设置单元格的编辑样式(目的:none?insert?delete?对哪些行进行设置?)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
如果进行单元格的移动操作,对应下面这个函数
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
4、(特性2)根据单元格的样式对单元格进行操作(如果删除样式?那么删除数据源,更新UITableViewCell,如果是添加样式?那么增加数据源,更新UITableView。)
5、其他特性- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
如果进行单元格的移动操作,对应下面这个函数
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
5.1 是否可以多选(默认不可以)
@property(nonatomic) BOOL allowsMultipleSelection NS_AVAILABLE_IOS(5_0);
5.2 对单元格的操作(对UITableView的数据进行操作:增删移动之类的)
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0); - (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_AVAILABLE_IOS(5_0); - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0); - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_AVAILABLE_IOS(5_0);