• (四十二)tableView的滑动编辑和刷新 -局部刷新和删除刷新 -待解决问题


    tableView的局部刷新有两个方法:

    注意这个方法只能用于模型数据的行数不变,否则会出错。

    [self.tableView reloadRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>]

    对于删除数据的刷新(行数改变),应该调用下面的方法:注意传入的是indexPath数组。

    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    Tip:模型数据删掉的个数要和indexPath数组的长度相同。


    删除数据的代理方法:只要实现了这个方法就可以进行局部刷新。

    /**
     *  滑动删除和编辑功能
     *
     *  @param tableView    要操作的tableView
     *  @param editingStyle 编辑还是删除
     *  @param indexPath    编辑和删除的位置
     */
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            [self.RecentlyDB.RecentlyArray removeObjectAtIndex:indexPath.row];
        }
        
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }

    Tip:对于UIBarButtonItem,没有addTarget方法,需要分别设定target(面向的控制器)和action(selector包装的方法)。

    tableView进入编辑状态:

    [self.tableView setEditing:YES animated:YES];

    编辑状态的样式:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
        return UITableViewCellEditingStyleInsert;
    }

    编辑状态的实质是移动contentView。

    有时候编辑状态进入后不出现减号

  • 相关阅读:
    深度探索C++对象模型之第一章:关于对象之对象的差异
    深度探索C++对象模型之第一章:关于对象之关键词所引起的差异
    C++之constexpr
    STL之空间配置器
    10泛型算法
    C++之指针与数组区别
    数学 之 hdu 4861
    贪心 之 hdu 4864
    01背包(求前一个的最大价值-->求前K个的最大价值) 之 hdu 2639
    01背包(体积为负,改变区间) 之 poj 2184
  • 原文地址:https://www.cnblogs.com/aiwz/p/6154209.html
Copyright © 2020-2023  润新知