Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

ios - UITableViewCell具有动态高度以防止单元重用:如何避免落在调整大小的乒乓循环中?(UITableViewCell with dynamic height against cell reuse : how to avoid falling in a resize ping-pong loop?)

So here's the description of the loop my app keeps falling on:

(所以这是我的应用程序不断循环的描述:)

There is a UITableView containing ReactiveTableViewCell's (but I think RX part doesn't really matter here, so let's pretend these are UITableViewCell).

(有一个包含ReactiveTableViewCell的UITableView(但是我认为RX部分在这里并不重要,所以我们假装它们是UITableViewCell)。)

Each cell embeds a UITextField upon an expandable/collapsable UIView (that allows me to show any error message related to the textfield) - when there is no error to show, this subview is collapsed .

(每个单元格将UITextField嵌入到可扩展/可折叠的 UIView上(这使我可以显示与文本字段相关的任何错误消息)-当没有错误要显示时,此子视图将折叠 。)

The thing is, when UITableView gets scrolled and makes reuse of an "errored" cell, the subview of this cell is still expanded .

(问题是,当UITableView滚动并重新使用“错误的”单元格时,该单元格的子视图仍会扩展 。)

As PrepareForReuse() method is made to reset cell state before a reuse, I thought it would be the right place to collapse the subview, and indeed it does... until the app falls into a loop, resizing top-screen and bottom-screen same cell forever.

(由于在重新使用之前使用PrepareForReuse()方法来重置单元格状态,所以我认为这是折叠子视图的正确位置,确实如此……直到应用程序陷入循环,调整顶部屏幕和底部的大小,永远筛选同一单元格。)

How do you think I could fix this issue?

(您认为我如何解决此问题?)

Maybe is there a way to increase cell reuse tolerance so UITableView won't reuse a cell as soon as it disappeared from screen?

(也许有一种方法可以提高单元重用的容忍度,以便UITableView不会在屏幕消失后立即重用它?)

Maybe shall I have a try with a resize-lock while list is being scrolled, but it will always leave some margin for error so it's not the fix I'm looking for.

(在滚动列表时,也许我可以尝试使用大小调整锁定,但是它总是会留一些误差,因此这不是我要寻找的解决方案。)

Thanks for your help.

(谢谢你的帮助。)

  ask by leeyo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...