iOS TableView的左划删除以及多个分区的删除某一行的个人笔记

本文介绍如何在iOS应用中使用UITableView实现行项目的编辑与删除功能,包括设置删除按钮样式、确认删除提示及实际删除操作的方法。
  1. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
  2.     return YES; 

  3. -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath  
  4. {  
  5.     return UITableViewCellEditingStyleDelete;  
  6. }  
  7.   
  8. /*改变删除按钮的title*/  
  9. -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath  
  10. {  
  11.     return @"删除";  
  12. }  
  13.   
  14. /*删除用到的函数*/  
  15. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath  
  16. {  
  17.     if (editingStyle == UITableViewCellEditingStyleDelete)  
  18.     {  
  19.     /*此处处理自己的代码,如删除数据*/  
  20.    [dataArray removeObjectAtIndex:indexPath.row]; ( NSMutableArray)
  21. //删除对应分区中对应行的写
  22.     [[self.dataArray objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
  23.     /*删除tableView中的一行*/  
  24.     [tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];  
  25.  //报错则用 [self.tableView reloadData]; 
  26.     }  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值