zoukankan      html  css  js  c++  java
  • IOS开发之实现UITableView控件自带的删除功能方法

    点击删除Button后,列表左边出现一列红色减号图标,点击,对应这一行右侧的红色删除按钮会出来。

    直接把某行左滑也可以出来删除按钮

    这个功能是tableView自带的,要用这个功能,必须实现两个方法

    方法一:如下图中关键的一句.

    -(IBAction)deleteBU:(UIButton *)sender{
        //setedit animate让tableView进入可编辑模式
        [_recoderTableView setEditing:!_recoderTableView.isEditing animated:true];
    }

    方法二

    -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (editingStyle == UITableViewCellEditingStyleDelete){
    
    //删除数据源
    
    //删除刷新
     [self.recoderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    删除数据源这一块,我本人是把文件夹下的文件信息展示到tableView上,所以删除数据源我是获取路径,从cell拿当前文件名,拼接路径,删了这个文件。

    网上很多人转载的,基本上是一个数组,删除了对应下标的元素,removeObjectAtIndex啥的。我尝试过加这句话,从存了文件信息的数组里删除对应cell行的信息,不过一直报数组的错,大意是更新前和更新后,数目不一致什么的

    -[__NSArrayM removeObjectsInRange:]: range {1, 1} extends beyond bounds [0 .. 0]'

    所以我把这句removeObjectAtIndex就去掉了。

    我是边学边做的,数据源这块到底是怎么弄我也不清楚,给大家一个参考。

  • 相关阅读:
    CodeForces Gym 100500A A. Poetry Challenge DFS
    CDOJ 486 Good Morning 傻逼题
    CDOJ 483 Data Structure Problem DFS
    CDOJ 482 Charitable Exchange bfs
    CDOJ 481 Apparent Magnitude 水题
    Codeforces Gym 100637G G. #TheDress 暴力
    Gym 100637F F. The Pool for Lucky Ones 暴力
    Codeforces Gym 100637B B. Lunch 找规律
    Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
    TC SRM 663 div2 B AABB 逆推
  • 原文地址:https://www.cnblogs.com/kc1995/p/13158614.html
Copyright © 2011-2022 走看看