zoukankan      html  css  js  c++  java
  • iOS中tableview的几种刷新

    iOS中tableview的几种刷新

    第一种刷新:tableview的刷新   [self.tableView reloadData];

    reloadData是刷新整个UITableView,有时候,我们可能需要局部刷新。比如:只刷新一个cell、只刷新一个section等等。这个时候在调用reloadData方法,虽然用户看不出来,但是有些浪费资源。

    第二种刷新:刷新局部的cell

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];

    这样就可以很方便的刷新第一个section的第一个cell。虽然看起来代码多了,但是确实比较节省资源。尽量少的刷新,也是UITableView的一种优化。

    第三种刷新:局部刷新section

    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:0];

    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];

    上面这段代码是刷新第0个section。

    刷新动画

    刷新UITableView还有几个动画:

    typedef NS_ENUM(NSInteger, UITableViewRowAnimation) {

    UITableViewRowAnimationFade,   //淡入淡出

    UITableViewRowAnimationRight,  //从右滑入         // slide in from right (or out to right)

    UITableViewRowAnimationLeft,   //从左滑入

    UITableViewRowAnimationTop,     //从上滑入

    UITableViewRowAnimationBottom,  //从下滑入

    UITableViewRowAnimationNone,            // available in iOS 3.0

    UITableViewRowAnimationMiddle,          // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy

    UITableViewRowAnimationAutomatic = 100  // available in iOS 5.0.  chooses an appropriate animation style for you

    };

    1.NSIndexSet是什么?

    NSIndexSet  是个无符号整数集合。集合中的元素不可变的、不可重复。常被用来当作索引使用。就从它字面上理解,就叫做:索引集合。

  • 相关阅读:
    Java实现HttpClient发送GET、POST请求(https、http)
    解决.net core 3.1 json日期带T的问题
    Java验证身份证号码的格式
    c++20新特性concept
    位图
    Linux内核 hlist_head/hlist_node结构解析
    linux将c++程序制作成.deb
    应用程序或动态库中与加载的其他动态库的类或者函数重名问题
    vue props 属性值接受多个类型
    异步循环
  • 原文地址:https://www.cnblogs.com/Ninesday/p/5368768.html
Copyright © 2011-2022 走看看