iOS UITableView Bug - White line on every other tableview cell - ios

I have a weird bug in a UITableView I've implemented that uses custom cells.
Every other cell has a white line at the bottom of it. This line is only present on iPhone 5 and iPhone 6. It does not show on iPhone 6+. Two screenshots are provided from the iPhone 6 simulator (where you see the line) and the iPhone 6+ simulator (where you don't see the line).
I've tried every solution on stackoverflow but none of them are working. Namely, I've added the following methods to my table view:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if ([self.tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:#selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:#selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:#selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
and the following method to my custom cell:
- (UIEdgeInsets)layoutMargins {
return UIEdgeInsetsZero;
}
Yet the line is still seen on every other cell. Any ideas on how to get rid of this line? Thank you!

Please check your cell height in storyboard.if it is custom cell than confirm your cell height.
I faced same issue and my mistake was cell height.
Also check in .m file whether cell height method returns different height or not.
Otherwise check all view by applying different colors.

Related

Remove Separator from Grouped UItableview

I'm using an UITableView Style Grouped Seperator NO
When the table view loads I See a small distance between the cells.
and when scrolled it goes away
Need to get rid of that line. what is that I'm missing.
Use this, it will help you.
Write this in your viewDidLoad
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
And write this method for UITableView
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:#selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
Thanks All,
Have solved this by setting Bottom Constraint of the view to -1, and unchecked Clip To Bounds for both UITableViewCell and its Content View.

uitableviewcell separator line not displaying in full width

I am trying to display UITableview custom cell. but my tableview separator does not displaying as expected. I am attaching a screenshot.
I tried with making UIEdgeInsetZero but it did not worked. can anyone help me to fix this.
Setting separatorInset to UIEdgeInsetZero is not enough for iOS 8. You should also set layoutMargins property of table and cell to UIEdgeInsetZero.
Please kindly change the separator insets by custom. Thanks.
Try this:
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = NO;
Hey All I got the solution.
I override layoutSubviews in my Custom UITableViewCell and the separators are displayed properly.
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *subview in self.contentView.superview.subviews) {
if ([NSStringFromClass(subview.class) hasSuffix:#"SeparatorView"]) {
subview.hidden = NO;
}
} }
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:#selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:#selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}

UITableView looks right in simulator and wrong in actual device - iPhone 4s

I have a UITableView which loads fine in the simulator and all devices other than iPhone 4s. I have been searching for answers for a while and even put this on hold until now hoping that I would think of a solution but nothing seems to work.
The solution I tried was to remove possible conflicting code which is now commented like below.
// Remove seperator inset
if ([cell respondsToSelector:#selector(setSeparatorInset:)]) {
//[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:#selector(setPreservesSuperviewLayoutMargins:)]) {
//[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
//[cell setLayoutMargins:UIEdgeInsetsZero];
}
My current code looks like this
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
-(double) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 3) {
return 700.0;
}
return 44.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 3) {
static NSString *homeTableIdentifier = #"GeneralInfoTableViewCell";
GeneralInfoTableViewCell *cell = (GeneralInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:homeTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"GeneralInfoTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else if (indexPath.row == 2) {
...
Please note that I edited out the logo which shows up twice in this view which is why "erbjudanden" is cut off in the wrong view below.
This is what the view looks like in the iPhone 4s simulator (correct way).
This is what the view looks like on the actual iPhone 4s (wrong way)
What can I do to fix this issue?
I had issues here as my device was running iOS 10, whereas my simulator was running iOS 9.3.
I suspect that the view hierarchy calls happen in a slightly different order, resulting in the difference of display between the two.
A call to view.layoutIfNeeded() just before updating the required views helped me out.

Separator on the last UITableViewCell not added?

This is how my UITableView looks like:
I might cut the image to close to the last cell but there is no separator on the last cell.
When running this on my device that has IOS 7.1.1 It gets the same result until i scroll the view up and down a bit and then it automatically adds the separator. But trying that in the simulator which is running on IOS 8.2 as you can se nothing happens.
So what i want is simply so the separator is visible from the start.
Many thanks
EDIT1
After trying the answer below it did work however when there are a lot of cells and you scroll up then an extra separator shows up as you can see.
Check the third last cell. That extra separator just follows me when i go up and down.
EDIT2
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:#selector(setSeparatorInset:)])
{
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:#selector(setSeparatorInset:)])
{
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:#selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0)
return 76.0f;
else
return 25.0f;
}
Use the two below UITableView delegate methods
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* view = [UIView new];
[view setBackgroundColor:[UIColor grayColor]];
return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0f;
}
Try to add footer view for table with 1 0r 2 pixel height.
This worked flawlessly for me
self.tableFooterView = [[UIView alloc] init]

iOS8: Separator zero and accessory view disclosure indicator

I've read about how to make the cell full width again in iOS 8 so the separator extends to the left edge.
-(void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:#selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:#selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
However after my view controller is loaded the disclosure indicator and the label left of it "jump" a little bit further left, which the user can see. I've set the constraints of the label to "Trailing space of label to Superview x". So why is there this jump? How can I avoid it? So annoying...I've also tried of setting the constraint not to the margin but relative to the view without the margin and the jump was still there

Resources