Group TableView,using self sizing section header,a

2019-03-02 16:59发布

I am doing a tableview like this: a twitter and comments on it; enter image description here

I have tried several architecture.I do not find enough question and discussion about this. I think it is a very meaningful question,so I post these architectures' performance and limitations.

First,using whole cell as twitter with comments,which comments view will generate according to the model.Cell use self-sizing auto-layout height.
This architecture can work.But if a twitter have many comments(30,or more),in old iPhone(4s,5,5s and so on),fps will down to 40.Obvious block for scroll smooth.This performance bottleneck is the only weakness for this architecture.

Second,because of performance bottleneck,I think maybe I could put a comment tableview in a twitter cell.And twitter cell and embedded comment cell use self-sizing auto-layout height,too.But after try,I found that twitter cell can not confirm its height because the embedded comment tableview can not confirm its height itself.So I need to calculate the embedded comment tableview's height to confirm the twitter cell's height. This architecture works well,too.But its performance bottleneck is the same as first architecture.

Third,also the most improtant,using section header as twitter,cell as comment.That is,a section is a whole twitter with comments.Section header and cell both use self-sizing auto-layout height.
This architecture's performance is best,even twitter with as many as 50+ comments,tableview scrolls very smooth even in iPhone5,fps is at least 55.But there is strange problems that I can not solve.
I scroll to the bottom,tableview will reload next page.After reloadData,first little problem is that section header dismiss,but appear after scroll(Later I found that if I set tableview header,this problem appear,if I remove tableview header,this problem disappear,so confused).Second and more important problem is that if I scroll upward,tableview will "jump".Below is the gif demonstration.(I do not know how to post big gif to StackOverflow,I am sorry) https://github.com/yutanchi/GroupTableViewSectionHeaderJump/blob/master/tableviewjump.gif
I think the reason is that tableview use the estimated section header height but not the actural section header height. I have searched much information but nothing can help me.I am so confused that If section header's self-sizing mechanism is the same as cell's self-sizing mechanism.Why self-sizing cell can perform the right behavior,self-sizing section header do not. Because this architecture have obvious performance advantage,I want to make certain what's wrong with self-sizing section header,solve these annoying problems and use the architecture.Can someone explain or discuss this?

1条回答
Lonely孤独者°
2楼-- · 2019-03-02 17:25

For this you have to give all constrains left right top bottom to all elements. Also 1-in viewDidLoad set following

self.yourtableView.estimatedRowHeight= your estimated_height_for_Cell
yourtableView.rowHeight = UITableViewAutomaticDimension

2-set number of rows to zero For Labels in attribute inspector.

查看更多
登录 后发表回答