UITableView对于iOS开发者来说一定不会陌生,很有可能你的APP很多界面都用到它。关于UITableView的文章,想必已经不计其数,没事可以多看看。特别是UITableView优化的文章,非常值得仔细琢磨一番。

今天我们来看看如何刷新UITableView的,一般情况下,刷新UITableView,我们会直接调用reloadData方法。

刷新UITableView

[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

};

刷新 tableview的更多相关文章

  1. 李洪强iOS开发之 - 指定刷新tableview的某一组

    李洪强iOS开发之 - 指定刷新tableview的某一组

  2. 自定义刷新tableView

    // //  LSTWholeTableController.m //  BUDEJIE // //  Created by admin on 16/8/17. //  Copyright © 201 ...

  3. 在模型中获取网络数据,刷新tableView

    model .h #import <Foundation/Foundation.h> #import "AFHTTPRequestOperationManager.h" ...

  4. iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除

    首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...

  5. IOS详解TableView——内置刷新,EGO,以及搜索显示控制器

    内置刷新 内置刷新是苹果IOS6以后才推出的一个API,主要是针对TableViewController增加了一个属性,refreshControl,所以如果想用这个内置下拉刷新的话,最好给你的Tab ...

  6. TableView刷新 局部刷新等

    1.对整个页面刷新 [ tableView reloadData]; 2.对某一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithI ...

  7. 新浪微博客户端(18)-集成下拉刷新控件UIRefreshControl

    HomeViewController.m - (void)setupPullToRefreshView { UIRefreshControl *refreshControl = [[UIRefresh ...

  8. [iOS基础控件 - 6.9.3] QQ好友列表Demo TableView

    A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组   code so ...

  9. iOS开发UI篇-实现tableView的层级显示

     进来要实现一个tableView 的cell层级显示,网上找的思路都各不相同.下面说一下我的实现思路.  根据根标题存储cell的展开状态,添加到字典中. 话不多说,直接上代码. #define S ...

随机推荐

  1. 使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案

    一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...

  2. HTML5屏幕适配标签设置

    开发HTML5游戏中,我们常用的一些mata标签: <meta name="viewport" content="width=device-width, initi ...

  3. HTML&CSS基础学习笔记1.7-高亮文本及组合使用

    HTML提供了<mark>标签可以让你的文本高亮,这样看起来更加醒目.<mark>标签内的文本会呈现特殊的样式,它和<em>,<strong>一样也是一 ...

  4. Kafka笔记--使用ubuntu为bocker(服务器)windows做producer和comsumer(客户端)

    原文连接:http://www.cnblogs.com/davidwang456/p/4201875.html 程序仍然使用之前的一篇博文中的例子 :http://www.cnblogs.com/gn ...

  5. shell编程技术之-基础知识

    一.脚本结构 linux下shell的脚本,是将一系列命令序列写在一个文本文件,而这个文本文件时可执行的.相对命令行来说,开发效率提高.因此他的构架有2部分构成#!和命令序列.其中#!指明此脚本是用哪 ...

  6. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  7. Row Cache Objects

    This latch comes into play when user processes are attempting to access or update the cached data di ...

  8. Java Access Levels(访问控制)

    Access Levels Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y ...

  9. HTML--控制小人自由移动

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. delphi 简单的删除字符串尾部数字的代码

    delphi  简单的删除字符串尾部数字的代码 方式一: function FilterShowName(const sName: String): String; var I: Integer; b ...