UITableViewCell separator not showing up

不羁岁月 提交于 2019-11-28 08:56:06

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 overriding layoutSubviews make sure no views are obscuring the bottom of the cell.

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%

In my case, i forgot to call [super layoutSubviews] after overriding the layoutSubviews method. Took me two hours to find the problem.

in my case I have to set the separatorStyle property of the tableView

tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

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.

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 a UIView element with custom class specified to be AddressBookTableView. I deleted this element and added a UITableView 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 custom UITableView elements NOT renamed UIView 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?

If you programmatically add subviews to your cell, make sure you add the subviews

to cell.contentView and NOT to cell

[cell.contentView addSubview:subview];

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!