UISegmentedControl 使 UITableView 变慢/滞后?
所以我有一个工作良好的 UITableView,由 3 行组成(每行包括图像,以及不同数量的文本字段)。
现在第 4 行有一个 UISegmentedControl。一旦我添加它,UITableView 就会滞后/跳跃/跳过。当我再次把它拿走时,一切都顺利了。
如何添加 UISegmentedControl 并仍然平滑滚动?
So I have a nicely working UITableView consisting of 3 rows (each including and image, and a varying number of text fields).
Now the 4th row has a UISegmentedControl. As soon as I added it, the UITableView lags/jumps/skips. When I take it away again, everything is smooth.
How can I add the UISegmentedControl and still have smooth scrolling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有类似的问题。分段控件消失后,滚动回该控件会出现断断续续的情况。问题可能是初始化。
首先检查您是否正确使用“dequeueReusableCellWithIdentifier”(也许您错过了为自定义单元格提供唯一的ID?)
第二次检查您是否每次都在cellForRowAtIndexPath中执行removeAllSegments和insertSegmentWithTitle。在自定义单元格中添加一些 int 来告诉您它是新单元格还是具有一定数量段的重用单元格。然后,在“dequeueReusableCellWithIdentifier”之后,如果单元格具有确切数量的段,则不需要清除和添加。
就我而言,我检查了第一个,但没有检查第二个,这使得我的滚动滞后。看来,段的清除和添加是一个代价高昂的操作。
希望这有帮助。
Had a similar problem. After the segmented control goes out of view, scrolling back to it is choppy. The problem could be the initialization.
First check if you use the "dequeueReusableCellWithIdentifier" correctly (maybe you missed giving your custom cell a unique ID ?)
Second check if you don't do removeAllSegments and insertSegmentWithTitle each time in cellForRowAtIndexPath. Add some int to your custom cell to tell you if it is a new cell or a reused cell with a certain number of segments. Then after you "dequeueReusableCellWithIdentifier" if the cell has the exact number of segments no clearing and adding is needed.
In my case I did the checked the first but not the second which made my scrolling lag. It seems that the segment clearing and adding is a costly operation.
Hope this helps.
我也有类似的问题。由于业务逻辑,我的应用程序应该以几秒钟的间隔更新单元格。每个单元格都有一个分段控件,我删除了所有分段并在每次更新时再次添加它们。一段时间后,滚动变得非常慢。我解决了仅在确实需要时删除/添加段的问题,而不是为每次更新都执行此操作。我还使用“dequeueReusableCellWithIdentifier”。现在工作正常。
I had a similar problem as well. Due to business logic my app should update the cells for an interval of a few seconds. Each cell had a segmented control and I was removing all segments and adding them again for each update. After some time the scrolling gets incredibly slow. I solved the problem removing/adding the segments only when it was really necessary instead of doing this for each update. Also I'm using "dequeueReusableCellWithIdentifier". It is working fine now.