UITableViewCell separator not showing up

2019-01-18 08:51发布

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!

8条回答
Viruses.
2楼-- · 2019-01-18 09:16

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-18 09:17

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.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-18 09:20

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.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-18 09:24

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

查看更多
看我几分像从前
6楼-- · 2019-01-18 09:25

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

tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

查看更多
家丑人穷心不美
7楼-- · 2019-01-18 09:27

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?

查看更多
登录 后发表回答