简体   繁体   中英

iOS UITableView Bug - White line on every other tableview cell

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).

iPhone 6屏幕截图 在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM