像FaceBook一样滚动UITableView [英] Scrolling UITableView like FaceBook

查看:72
本文介绍了像FaceBook一样滚动UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果查看iOS的Facebook"App",则UITableView的滚动非常快.看来该应用程序正在将数据呈现到不同线程(而不是主线程)中的单元格中.

If you look into Facebook "App" for iOS, scrolling of the UITableView is very fast. It seems like the app is rendering data into cell in different thread (not in main thread).

我也在开发类似的应用程序.但是我的应用滚动速度不好.我正在使用图像的延迟加载.即使这样,滚动速度还是很差.

I'm also developing a similar application. But my app scrolling speed is not good. I'm using lazy loading of images. Even then the scrolling speed is poor.

是否可以在其他线程(而不是主线程)中填充自定义UITableViewCell?

Is it possible to populate custom UITableViewCell in different thread (not in main thread)????

感谢您的回复

推荐答案

假设每个UITableViewCell有以下任务

Suppose You have Following Tasks Per UITableViewCell

  1. 从服务获取数据
  2. 从服务中获取图片
  3. 调整图像大小以匹配容器大小<​​/strong>(如果获得的图像较大,则应执行此操作)
  4. 显示您的数据.
  1. GetData From Service
  2. Fetch Image from service
  3. Resize image To match container size (You should do this if image you get is large)
  4. Display your Data.

您应该在后台执行1,2,3

You Should perform 1 , 2 , 3 in Background

但是您必须这样做,并且应该在主线程中执行4.

不要为每个表视图单元格创建单独的线程 ,然后针对任务1、2、3再创建3个线程.这确实浪费了资源.

Don't create a separate thread for each and every tableview cell and then again 3 for tasks 1 , 2 , 3. Its really wasting of resources.

那么如何在不为每个事物创建线程的情况下完成所有这些背景工作.

So How you can do all these background without creating a thread for each and every thing.

使用大中央配送(GCD)

在GCD上阅读.

如果您想要一种快速的解决方法,那就在这里

If you want a quick workaround Here it is

好吧.任务编号4有两件事要做.

Well. Task Number 4 has two things to do.

4(a)更新表单元格上有关日期"的文本. 4(b)显示已获取并调整大小的图像.

4(a) Update Some text on table cell for Date we get. 4(b) Display Fetched and Resized Image.

我正在服用
1 4(a)

I'm Taking
1 and 4(a)

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

       1. DO 1 Here
       2. Call a Call Back When your Task is Done
        example
        CallBack(Response);

});


CallBack(Response *)response{

   dispatch_async(dispatch_get_main_queue(), ^{

        Do your 4(a) Here
   });
}

这篇关于像FaceBook一样滚动UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆