简体   繁体   中英

tableview smooth scroll best practices swift

It's a technical question, or about good practices...

I have this App, its a social network, where we have the timeline. In this timeline I have to render a lot of cells on a tableview which I have done this way:

  • create a Cell (with header, body and footer) -xib file
  • in this cell I have a method: setupCell() - which configures the contents
  • for each kind of post I instantiate a correctly view(xib) on body of this cell (like PhotoPost, TextPost or VideoPost etc) and configure constraint to set the size of views.
  • Also, I'm using:

      tableView.estimatedRowHeight = 603 tableView.rowHeight = UITableViewAutomaticDimension 
  • And kingfisher to download images asynchronous.

And, what is best way: storyboard, xib, or code?

So, my problem is that my scroll is lagging - I'm using reusable cells, but every time that tableview delegate calls cellForRow, I have to setupCell().

My first idea: I get the post array with a task then a create cells for each post and append this to an array of cells, so when cellForRow is called I just get the right cell from this array.. It make better. But still not enough(I'm testing on a iPhone 5c). My next ideia is create different cell for each kind of post, and save a variable for this cell of his size to setup on heighForCell method. You think that looks good solution? Can anyone give me an opinion and suggestion? I'am very tankful in advance..

After experimenting with possible solutions I decided to use AsyncDisplayKit to solve my problem, it offers great smooth scrolling.

http://asyncdisplaykit.org

It's complete SDK and has well written documentation so was easy to implement. I would recommend it if you are struggling with a similar issue to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM