Ios UITableViewCell programmatically creates in drawRect vs layoutSubviews

I'm trying to create a complex UITableViewCell through Autolayout, but it gives a huge performance delay during scrolling, so I decided to go for a programmatic approach to the frame.

The complexity of cell layout is similar to Facebook cards, where each cell is different from wrt in dynamic text and images.

I tried to display the cell in layoutSubviews , but the scrolling is still bad, but better than Autolayout.

I also tried displaying the cell in drawRect , and this gives better performance, but during scrolling I cannot update the frames, because it is called only once.

Can someone help me what is the best way I can go with better scroll characteristics? I am stuck.

+5
source share
1 answer

I also came to the same exact conclusion that using the storyboard of witty restrictions becomes too slow when working with cells of a certain complexity. I had over 10 different types of cells. In this case, I had to use frames.

I am afraid that there is no other way than to lay out your cells, using the framework of your ideas of your child. Using the methods heightForRowAtIndexPath and cellForRowAtIndexPath, you can completely style your cells.

The first method, called cellForRowAtIndexPath. In this method, you fully customize your cells, laying out your views, etc. After you have done everything you can also determine the height of your cells. Then you can simply select the cell height from the frame of the parent view and use it.

In heightForRowAtIndexPath you can have one row returning the height of the cell if you instead saved the height in an array.

I kind of ignored layoutsubviews methods since I had to reorganize a bunch of existing code. However, I posted the cell only in cellForRowAtIndexPath, and not in the layoutsubviews method. In this method, I can use the height of the child views to calculate the height of the parent. In layoutsubviews, the views will be laid out later, and this can cause problems.

In any case, this information is useful to someone.

0
source

Source: https://habr.com/ru/post/1246382/


All Articles