ios

iOS - UITableView删除section

2017-05-19  本文已影响1173人  HanZhiZzzzz
// 删除

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{

            return  UITableViewCellEditingStyleDelete;

}
// 改变删除按钮的title

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 
{

           return @"删除";

}
// 删除用到的函数

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

         if (editingStyle == UITableViewCellEditingStyleDelete)

          {

             [self.dataArr  removeObjectAtIndex:[indexPath section]];  //删除数组里的数据

             [self.tableV deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]                     withRowAnimation:UITableViewRowAnimationAutomatic]; //删除对应数据的cell
/*
   [self.dataArr  removeObjectAtIndex:idx];  //删除cell
                [self.tableV deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:idx inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];

*/
         }

}
上一篇下一篇

猜你喜欢

热点阅读