我正在做一个这样的表格视图:推特和评论;在此处输入图片描述
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.
首先,将整个单元格用作带有评论的twitter,评论视图将根据模型生成.单元格使用自动调整大小的自动布局高度.
这种架构可以工作.但是如果一个 twitter 有很多评论(30 或更多),在旧 iPhone(4s、5、5s 等)中,fps 将下降到 40.滚动平滑的明显块.这个性能瓶颈是这种架构的唯一弱点.
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.
第三,也是最重要的,使用section header作为twitter,cell作为comment.也就是说,一个section是一个带有评论的整个twitter.section header和cell都使用self-sizing auto-layout height.
这个架构的性能是最好的,即使是评论多达50+的twitter,即使在iPhone5中tableview滚动也非常流畅,fps至少是55.但是有一些奇怪的问题我无法解决.
我滚动到底部,tableview将重新加载下一页.reloadData后,第一个小问题是节标题消失,但滚动后出现(后来我发现如果我设置tableview标题,就会出现这个问题,如果我删除tableview标题,这个问题消失了,很困惑).第二个也是更重要的问题是,如果我向上滚动,tableview 会跳".下面是 gif 演示.(我不知道如何将大 gif 发布到 StackOverflow,对不起)https://github.com/yutanchi/GroupTableViewSectionHeaderJump/blob/master/tableviewjump.gif
我认为原因是 tableview 使用估计的节标题高度而不是实际的节标题高度.我搜索了很多信息,但没有任何帮助不是.因为这种架构具有明显的性能优势,所以我想确定 self-sizing section header 有什么问题,解决这些烦人的问题并使用该架构.有人可以解释或讨论一下吗?
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-in viewDidLoad 设置如下
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-在属性检查器中为标签设置行数为零.
2-set number of rows to zero For Labels in attribute inspector.
这篇关于分组 TableView,使用自定大小的部分标题,重新加载后,如果我向上滚动,tableview 会跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!