UITableViewCell 分隔符未显示
我在 IB 中制作了一个自定义 UITableViewCell,但由于某种原因,尽管选择了分隔符的单行选项,但我的表格上没有分隔线。
你们中有人以前发生过这种情况吗?什么给?
谢谢!
I made a custom UITableViewCell in IB, but for some reason, despite the single line option for separator being selected, there are no separator lines on my table.
Has this happened to any of you before? What gives?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
IB 中的 UITableViewCell 是否与重写
drawRect:
的 UITableViewCell 子类关联?如果是这样,请确保您正在调用超级实现,因为这就是在底部绘制界限的原因。如果您要覆盖layoutSubviews
,请确保没有视图遮挡单元格的底部。Is the UITableViewCell in IB associated with a UITableViewCell subclass that overrides
drawRect:
? If so, make sure you are calling the super implementation, as that's what draws the line at the bottom. If you are overridinglayoutSubviews
make sure no views are obscuring the bottom of the cell.请注意,即使这是一篇旧帖子:
如果您使用模拟器并且 UITableView 分隔符未显示在单元格之间,则可能是由于您的窗口比例太小。
通过转到“窗口”->“比例”->100% 来更改此设置
Just a heads up even though this is an old post:
If you are using the simulator and the UITableView separator is not showing up between cells it may be due to the fact that your window scale is too small.
Change this by going to Window->Scale->100%
就我而言,我在重写layoutSubviews方法后忘记调用[superlayoutSubviews]。我花了两个小时才找到问题所在。
In my case, i forgot to call [super layoutSubviews] after overriding the layoutSubviews method. Took me two hours to find the problem.
就我而言,我必须设置 tableView 的separatorStyle 属性
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
in my case I have to set the separatorStyle property of the tableView
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
我在 UITableView 类参考。
它表示它将向委托方法返回的单元格添加separatorStyle, tableView:cellForRowAtIndex:。
所以,我认为你应该修改 UITableView 实例上的 style 属性。
I found
separatorStyle
in UITableView class reference.It says it will add separatorStyle to the cell returned by the delegate method, tableView:cellForRowAtIndex:.
So, I think you should modify the style property on the UITableView instance.
对于看到此内容的任何人:我的问题是我有多个部分,并且每个部分中的第一个单元格没有分隔符。在我的表视图中,我覆盖了 heightForHeader 函数(返回 0)。删除此解决了该问题。
For anyone seeing this: My issue was that I had multiple sections, and the first cell in each section didn't have a separator. In my table view, I had overwritten the heightForHeader function (returning 0). Deleting this fixed the issue.
也许这是一个不太可能发生的情况,但还有另一个可能的原因。
我有一个名为 AddressBookTableView 的自定义 UITableView,它包含在我的视图控制器之一的 .XIB 中。我注意到它已被添加为 UIView 元素,并将自定义类指定为 AddressBookTableView。我删除了这个元素并添加了一个
UITableView
元素,而不是我再次指定其类为 AddressBookTableView 并且分隔符神奇地重新出现了!我花了很长时间才找到这个...
确保您的自定义
UITableView
.XIB 元素确实是自定义UITableView
元素,未重命名为UIView 元素。
说实话,我很惊讶这个错误唯一明显的假象是分隔符丢失了。除此之外 UITableView 仍然正常工作吗?
Maybe an unlikely case, but there's another possible cause.
I have a custom
UITableView
called AddressBookTableView and it is included in a .XIB for one of my view controllers. The thing I noticed was that it had been added as aUIView
element with custom class specified to be AddressBookTableView. I deleted this element and added aUITableView
element instead whose class I again specified to be AddressBookTableView and the separators magically reappeared!Took me a super long time to find this...
Make sure your custom
UITableView
.XIB elements are indeed customUITableView
elements NOT renamedUIView
elements.To be honest I'm surprised that the only noticeable artifact of this mistake was that the separators were missing. Other than that the UITableView still functioned normally?
如果您以编程方式向单元格添加子视图,请确保将子视图添加
到 cell.contentView 而不是 cell
If you programmatically add subviews to your cell, make sure you add the subviews
to cell.contentView and NOT to cell