-1

I'm developing an iPhone application similar like Facebook ,but for different purpose. I'm having an array of data for each and every row in UITableView i.e content,photos,no.of likes,comments,title etc. I'm having custom cell ,which inherits UITableviewcell,in which I have created all my UI objects such as UIIMageView,UILabel,UIButton etc. While scrolling my UITableView I will feed my data to this custom cell and it works fine.

My issue is the scrolling speed!

Whenever I'm scrolling, there is struck in it and the scrolling is slow. All my UI components assignment are done in main thread.

Is there any way to increase the scrolling speed or to assign value to my UI components in separate thread?

DD_
  • 7,230
  • 11
  • 38
  • 59
vishnu
  • 113
  • 5
  • Possible duplicate of [UITableView with images scrolls very slowly](http://stackoverflow.com/questions/12703297/uitableview-with-images-scrolls-very-slowly) – Patrick Aug 02 '16 at 12:16

6 Answers6

2

Thats the problem, All my UI components assignment are done in main thread. !!

Main thread should not be used to fetch urls or other resources. It will affect the user experience. Fetching image urls etc should be performed in a separate background thread and then when the download is complete update the main thread with the image data. This should solve your problem.

Also figure out what tasks are getting performed in main thread and see which ones are not UI related, move these tasks to background threads...

Lazy load images in UITableViewCell

Community
  • 1
  • 1
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
0

You can do it in following way:

1) Take custom tableview cell. (not necessary, but better for good looking and optimized code).

2) Implement LazyLoading for image in cell.

Lazy Loading is good way for your scrolling fast as well memory optimization.

You will get ready demo for Lazy Loading in table view and also apple provides the same.

This will resolve your issue.

Cheers and Happy Coding!

Nishant B
  • 2,897
  • 1
  • 18
  • 25
0

This problem is arises due to the downloading of images. Table cells are created when you scroll down the table and other cells are released..When cells are created the it downloads image for that cell and thats why main thread paused at that time. when image is downloaded it moves to next cell.

You need to download images in another thread not in main thread. A sample code on developers.apple.com is provided already pls check this. I think it helps you.

sample project code of lazy Loding

Satish Azad
  • 2,302
  • 1
  • 16
  • 35
  • I have stop loading images.Now only contents are been set ,along with that im also setting frame (CGRect) for my UI components.Even then it is affecting my scrolling speed – vishnu Jan 03 '13 at 09:44
  • Scrolling speed is effect only when there is a large amount of data that are loaded on cell view. Pls load data on cell in a new separate thread not in main thread. You can also us queueing of multiple tasks – Satish Azad Jan 03 '13 at 10:50
0

Try below links to create lazy loading in tableview, that will make your tableview scroll smooth

https://github.com/enormego/EGOImageLoading

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

Happy Coding!!!!

NiravPatel
  • 3,260
  • 2
  • 21
  • 31
  • I have stop loading images.Now only contents are been set ,along with that im also setting frame (CGRect) for my UI components.Even then it is affecting my scrolling speed. – vishnu Jan 03 '13 at 09:35
0

I don't know if I actually got what you were asking, but when you scroll your tableview, does it seems like it's lagging? because of fetching data?

Try this: https://github.com/rs/SDWebImage

Instructions are very easy to follow and understand.. That's what I did when I try to make my Youtube feeds (with images, video titles, vide description, date posted, etc). Hope it can help you

JCurativo
  • 713
  • 6
  • 17
0

I use AsyncImageView for loading images in UITableViewCells

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176