Remove SeparatorInset on iOS 8 UITableView for Xco

2020-01-26 03:20发布

I found a weird white space on UITableView for iPhone 6 Simulator (iOS 8) on Xcode 6 GM. I have tried to set the SeparatorInset from both storyboard and also the code, but the white space is till there.

The following code works on iOS 7 but not on iOS 8 (iPhone 6 simulator).

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}

I attached screenshot below:

iPhone 6 Simulator weird white space on tableview

I am using AutoLayout by the way. I hope someone can show me a way to remove the weird white space on the TableView.

15条回答
迷人小祖宗
2楼-- · 2020-01-26 03:57

In iOS8 you have to set the Inset both on Row and on Table level.

Row level in the cellForRowAtIndexPath:

if ([cell respondsToSelector:@selector(preservesSuperviewLayoutMargins)]){
    cell.layoutMargins = UIEdgeInsetsZero;
    cell.preservesSuperviewLayoutMargins = false;
}

Table level in the viewDidLoad:

[tableReference setSeparatorInset:UIEdgeInsetsZero];

After that it is a good idea to CLEAN your project. On some occasions I noted that these changes were not directly introduced in the executable App in the simulator.

查看更多
Fickle 薄情
3楼-- · 2020-01-26 04:01

In my case in Xcode 6.2, in addition to Will Q's answer, I have to go to Main.storyboard > select the UITableViewCell > Attributes Inspector. Change Separator dropdown list from Default Insets to Custom Insets. Change the left inset from 15 to 0.

enter image description here

查看更多
啃猪蹄的小仙女
4楼-- · 2020-01-26 04:01

Add startup images for iPhone 6 and Plus. Before the images are added the phone is running in scaling mode, i.e. older Apps get scaled to fit the new screen sizes. This may be causing the lines. The new images are Retina HD 5.5 (iPhone6Plus) 1242x2208 and Retina HD 4.7 (iPhone6) 750x1334.

查看更多
登录 后发表回答