有关动态调整标签和行高(iOS)大小的问题 [英] Issues regarding dynamic resizing of label and row heights (iOS)

查看:109
本文介绍了有关动态调整标签和行高(iOS)大小的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:


  • 构建一个应用程序,该应用程序填充一个从asyc json转储中接收数据的表。

  • 单元格属于自定义类(我定义)。单元中的主要标签可能很长。

  • 将其放置在原型单元中的情节提要中,但通过代码(相当标准的东西)进行自定义。

  • 在cellForRowAtIndexPath和行中调整标签的大小通过heightForRowAtIndexPath调整大小-通过强制调用cellForRowAtIndex来调整行的大小,例如Massimo的答案在这里

  • Building an app that populates a table that takes in data from a asyc json dump.
  • The cells are of a custom class (I defined). The main label in the cell can be very long.
  • It is "placed" in storyboard within a prototype cell but customized via code (pretty standard stuff).
  • Labels are resized in cellForRowAtIndexPath and rows are resized via heightForRowAtIndexPath -- rows are resized by forcing a call to cellForRowAtIndex like Massimo's answer here

因此,根据手头的问题-我已经注意到发生了一些有趣的(坏)事情。

So per the question at hand - I've noticed some interesting (bad) things that happen.

第一个问题:当表加载时,行和标签的大小会动态正确调整!大!但是,当我向下滚动然后向上滚动时,标签的高度将是错误的-例如,第一行在加载时是正确的。然后,当我向下滚动然后向上滚动以再次查看时,它将被截断。具体来说,行大小会很好,但标签高度会发生变化,仅被截断为2行。想知道这是否是因为我同时进行了情节提要和编码来定制单元。

First issue: When the table loads, the rows and labels are dynamically resized correctly! Great! However, when I scroll down and then scroll back up, the label heights will be incorrect -- (for example) the first row was correct at loading. Then when I scroll down and then scroll back up to see it again, it will be truncated. Specifically, the row size will be fine but the label height will change and become truncated to 2 lines only. Wondering if this is because I did both storyboard and coding to customize the cell. Anybody see this before?

第二个问题:当我向下滚动时,虽然行的大小正确(大),但标签很短(被截断了)。想知道是否有些标签与上述潜在答案相反。

Second issue: When I scroll down, while the rows are sized correctly (large), the labels are short (truncated.) Wondering if it's some reverse of the above "potential answer".


  • 潜在答案 是所有行都预先计算并存储,以便向下滚动/然后备份不会影响它。但是,当单元格不可见并出队时,当它们重新查看(向下滚动/然后向上备份)时,它将依赖情节提要。(不合适?)

  • "potential answer" is that the rows are all calculated and stored "up front" so that scrolling down/then back up doesn't affect it. However, when cells go "out of view" and are dequeued then when they re-viewed (scroll down/then back up) it will rely on the storyboard.(inappropriately?)

推荐答案

解雇,方法是从情节提要中删除原型单元,并将其完全放入代码中,因此问题消失了。基本的工作原理仍然不为人所知(例如,将单元放入队列然后再次查看时,情节提要与代码之间的交互作用)

"ANSWERED" by deleting the prototype cell from the storyboard and making them fully in code, the issue went away. The fundamental workings are still not understood (ie. the interactions between storyboard vs. code when cells are put queued and then viewed again)

这篇关于有关动态调整标签和行高(iOS)大小的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆