美文网首页ios
iOS - UITableView删除section

iOS - UITableView删除section

作者: HanZhiZzzzz | 来源:发表于2017-05-19 11:46 被阅读1173次
// 删除

- (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];

*/
         }

}

相关文章

网友评论

  • 90后的晨仔:你好我自定义的sectionView使用这种方法删除不了,请问还有其他的方法吗?

本文标题:iOS - UITableView删除section

本文链接:https://www.haomeiwen.com/subject/xhkyxxtx.html