UITableView 分隔线在滚动时单元格之间消失
问题:表视图中的单元格之间的分隔符仅针对视图加载时显示的单元格显示,并且仅在加载时显示。当表格视图向下滚动时,滚动到视图中的单元格之间不显示分隔符,然后当表格视图向上滚动时,初始单元格不显示分隔符。
详细信息:我有一个 UITableView,我要向其中添加标准 UITableViewCells。这些单元格是使用 initWithFrame 创建的,框架高度 = 90px。我将从笔尖创建的自定义视图添加到此单元格的视图中,高度 = 90px。单元格高度在 tableView:heightForRowAtIndexPath: 中指定为 90px。
有人经历过这种行为吗?
Problem: The separator between cells in a table view appear only for those cells shown when the view loads, and only at load time. When the tableview is scrolled down, the cells scrolled into view show no separator between them, then when the tableview is scrolled back up, the initial cells show no separator.
Details: I've got a UITableView to which I'm adding standard UITableViewCells. These cells are created with initWithFrame, frame height = 90px. I'm adding a custom view created from a nib to this cell's view, height = 90px. The cell height is specified at 90px in tableView:heightForRowAtIndexPath:.
Has anyone experienced this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有一种感觉,解决这个问题很简单......
我将单元格的高度设置为 91px,并且分隔线按照滚动时的样子显示。
I had a feeling the solution to this would be simple...
I made the height of my cells 91px and the separator lines appear as they should on scroll.
我无法使用道格拉斯的解决方案,因为我的桌子有大量的单元格,并且在旧手机上几乎无法使用。重复使用单元是性能的关键。
但是,我设法使用透明分隔符并在单元格的 contentView 中添加我自己的分隔符来解决该问题,如下所示:
I couldn't use Douglas's solution because my tables have a huge amount of cells and would become pretty much unusable on older phone. Reusing cells is key for performance.
BUT, I managed to workaround the problem using a transparent separator and adding my own in the contentView of the cell, as follows:
我有同样的问题,但我使用了不同的解决方案。
我的分隔符消失了,因为我正在使用以下方法清除单元格:
这也删除了分隔符视图!
相反,我在将每个自定义视图添加到子视图之前为它们分配了一个标签(三个标签):
然后,当我清除单元格时,我刚刚删除了这些视图:
希望这有帮助!
这也避免了@Douglas Smith 的解决方案带来的内存管理问题。
I had the same problem, but I used a different solution.
My separators were disappearing because I was clearing my cell using:
This removed the separator view as well!
Instead, I assigned a tag for each of my customs views (three labels) right before adding them to the sub view:
Then when I cleared the cell, I just removed those views:
Hope this helps!
This also avoids the memory management issues that @Douglas Smith's solution posed.
您应该将分隔符设置为无,然后再次设置单行
You should set separator none and then single line again