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!
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.
来源:https://stackoverflow.com/questions/3601013/uitableviewcell-separator-not-showing-up