5

I've been trying to create complex UITableViewCell through Autolayout but it is giving a huge performance lag while scrolling, So I decided to go for frame-based i.e programmatically.

The complexity of cell layout is like Facebook cards where every cell is different w.r.t to dynamic text and images.

I tried to render the cell in layoutSubviews but the scroll is still poor but better then Autolayout.

I also tried to render the cell in drawRect and this gives the best performance but while scrolling I can't update the frames as it is getting called only once.

Can someone guide me what is best case I can go with best scroll performance.? I am stuck .

Eiko
  • 25,601
  • 15
  • 56
  • 71
Mukesh
  • 3,680
  • 1
  • 15
  • 32
  • fb cards? couldn't you clarify? – m8labs Apr 04 '16 at 09:04
  • means fb news feed where image height varies and also the post – Mukesh Apr 04 '16 at 09:06
  • there are also could be comments, likes counters and other stuff.. I reproduced instagram cell with autolayout with acceptable perfomance (not so stunning as the original one though), thus without concrete sample it's difficult to tell what could be wrong with you solution. I believe fb and instagram do not use autolayout :) – m8labs Apr 04 '16 at 09:15
  • yes i know dey dont use autolayout , i read on many forums dey use `drawRect` method for performance as even i can see the performance is pretty good, but i am not able to crack tat stuff. – Mukesh Apr 04 '16 at 09:17
  • Use drawRect to draw your view. Nothing else. – gnasher729 Apr 19 '16 at 14:46

1 Answers1

0

I have also come to the same exact conclusion that using storyboards wit constraints becomes too slow when dealing with cells of a certain complexity. I had 10+ different types of cells. In this scenario I had to use frames.

I'm afraid there is no other way than to layout your cells using the frames of your child views. Using the heightForRowAtIndexPath and cellForRowAtIndexPath methods you can completely style your cells.

The first method that is called is the cellForRowAtIndexPath. In this method you completely style your cells laying out your views etc. Once you have done all that you can determine your cells height as well. You can then just fetch the cell height from the frame of your parent view and use that.

In the heightForRowAtIndexPath you can have a single line returning the height of the cell if you saved the height in an array instead.

I kind of ignored the layoutsubviews methods since I had to refactor a bunch of existing code. I however layed out the cell only in the cellForRowAtIndexPath and not the layoutsubviews method. In this method I can use the height of the child views to calculate the parent height. In the layoutsubviews the views are layed out later and that might cause issues.

Anyway hope this info is useful to someone.

Orion
  • 1,258
  • 2
  • 14
  • 32