ProgressCell用于显示文件传输的进度,困难点在于根据下载进度更新cell的进度条,先后尝试了几种方法:

1.有新的下载进度时,直接调用reloadData()

2.使用reloadRowsAtIndexPaths(),只更新进度条所在的 cell

这两种方法其实都是重新生成cell,重新设置内容,其实是重新绘制了整个cell.然而根据reloadRowsAtIndexPaths的api说明:

Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.

正确的方法是

3.我们需要改变cell显示的内容,数据有更新时,获取cell,更新cell的内容即可。使用update而非reload.如果cell不可见,那也不用更新了。

使用update很完美,而使用reload方法,有新的进度更新进度条时会发生闪动的现象。

reload方法与update方法的代码:

    func reloadAtIndex(index:Int) {
dispatch_async(dispatch_get_main_queue()) {
let indexPath:NSIndexPath = NSIndexPath(forRow: index, inSection: 0)
self.tableView.beginUpdates()
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
self.tableView.endUpdates()
}
}
//获取cell直接改变内容不会导致cell闪动,reload会重新生成cell导致闪动
func updateAtIndex(index:Int,msg:BaseMessage) {
dispatch_async(dispatch_get_main_queue()) {
let indexPath:NSIndexPath = NSIndexPath(forRow: index, inSection: 0)
if let cell = (self.tableView.cellForRowAtIndexPath(indexPath) as? ChatTableViewProgressCellA){
if msg is ProgressMessage{
let message = msg as! ProgressMessage
cell.time.text = message.time
cell.progress.progress = Float(message.transfered)/Float(message.total)
cell.content.text = message.text + (message.speed>=0 ? ":\(message.SpeedDescription)" : "")
}
} }
}

  

聊天界面之进度条cell(一)的更多相关文章

  1. 【液晶模块系列基础视频】4.5.X-GUI图形界面库-进度条等函数简介

    [液晶模块系列基础视频]4.5.X-GUI图形界面库-进度条等函数简介 ============================== 技术论坛:http://www.eeschool.org 博客地址 ...

  2. 聊天界面之气泡文本cell(二)使用Autolayout

    聊天界面主要是cell的动态高度计算和效率的问题,参考网上的两篇文章: 1.优化UITableViewCell高度计算的那些事  http://www.cocoachina.com/ios/20150 ...

  3. 聊天界面之气泡文本cell(一)

    在实现qq聊天界面的过程中,使用UITableViewCell碰到了不少问题,这里还是记录一下以免遗忘. 气泡聊天cell的实现,网上最多的方法还是: 1.手动计算设置frame的值,文本的size使 ...

  4. Qt带进度条的启动界面(继承QSplashScreen,然后使用定时器)

    通过继承QSplashScreen类,得到CMySplashScreen类,然后在CMySplashScreen中定义QProgressBar变量,该变量以CMySplashScreen为父类,这样就 ...

  5. NGUI的异步场景加载进度条

    1.直接创建三个场景,其中第二个场景是用来显示进度条加载的界面,进度条用UISlider,不会的看我前面的博文就可以了. 2.这里提供两种方法,建议使用第一种,加载比较平缓 方法一: using Sy ...

  6. WPF好看的进度条实现浅谈(效果有点类似VS2012安装界面)

    为了界面友好,一般的操作时间较长时,都需要增加进度条提示.由于WPF自带的进度条其实不怎么好看,而且没啥视觉效果.后来,装VS2012时,发现安装过程中进度条效果不错,于是上网查了资料.学习了Mode ...

  7. js控制进度条到达100%跳转界面一

    进度条一般在手机上用到的比较广泛,刚好最近的项目也是一直在做手机站,这个特效是手机端的一个界面,现在我把改成pc端了,进度条的快慢速度和样式可自行调节,改动也是很方便的,不多说,看代码: <st ...

  8. !!!!!安卓界面总是显示载入进度条的问题,没事别乱用ListFragment

    近期的安卓应用快完工了.可是个别界面有瑕疵,怎么改动都解决不了.挥之不去的阴影.问题例如以下: 在界面上,数据已经载入完成了.可还是有一股圆形的进度条,感觉它老是在载入什么东西,严重影响界面美观: 1 ...

  9. 怎样控制界面控件之进度条(ProgressBar)功能

    一.基础知识: 1.ProgressBar在界面文件XML中的布局: [html] <progressBar android:id="@+id/progressbar_updown&q ...

随机推荐

  1. float属性

    float属性介绍 float给人一种捉摸不透的感觉,不过可以依照浏览器的解析机制(根据HTML文档,从上往下解析),对float属性了解一二.float有四种值:none/left/right/in ...

  2. MVC中的Controller

    Controller是MVC模式中的三个核心元素之一. MVC模式中的Controller主要负责响应用户的输入, 并在响应时修改Model. MVC提供的是方法调用的结果, 而不是动态生成的页面. ...

  3. [Android Tips] 6. Parallax ViewPager

    文章 http://ryanhoo.github.io/blog/2014/07/16/step-by-step-implement-parallax-animation-for-splash-scr ...

  4. leetcode 111

    题目描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...

  5. php组成数组

    每次向数据库取5条数据,不足5条就不显示 $z = (int)(count($data) / 5);for ($ii = 1; $ii <= $z; $ii++) { foreach ($dat ...

  6. ubuntu15.04安装Chrome浏览器

    首先到: https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 下载最新的安装文件. 然后: sudo a ...

  7. css布局之左侧固定右侧自适应布局

    参考代码如下: <form id="form1" style="height:100%; overflow:hidden;"> <div st ...

  8. Java关于md5加密

    package com.mi.util; /** * md5+salt 长度为32的加密 * @author admin * */ public class MD5 { public static v ...

  9. 【过程改进】 windows下jenkins常见问题填坑

    没有什么高深的东西,1 2天的时间大多数人都能自己摸索出来,这里将自己遇到过的问题分享出来避免其他同学再一次挖坑. 目录 1. 主从节点 2. Nuget自动包还原 3. powershell部署 4 ...

  10. Using Yum Variables

    You can use and reference the following built-in variables in yum commands and in all Yum configurat ...