Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator

后端 未结 15 1982
情深已故
情深已故 2020-11-28 21:40

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 fr

相关标签:
15条回答
  • 2020-11-28 22:15

    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.

    0 讨论(0)
  • 2020-11-28 22:15

    See iOS 8 UITableView separator inset 0 not working

    Basically, you need to set both the cell.layoutMargin as well as the tableView's layoutMargin. YMMV, but I had to set the table view up in layoutSubviews before it would work!

    0 讨论(0)
  • 2020-11-28 22:17

    Try to create a UITableViewCell class category and add this getter

    - (UIEdgeInsets)layoutMargins {
        return UIEdgeInsetsZero;
    }
    

    in iOS7 this will not be called cos there's no this property in SDK,and will not cause any crash; in iOS8 this will be called every time you use the cell

    It works for me

    0 讨论(0)
  • 2020-11-28 22:17

    Workaround for iOS 7 & iOS 8

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {    
        cell.separatorInset = UIEdgeInsetsMake(0.0f, cell.frame.size.width, 0.0f, 0.0f); 
    }
    
    0 讨论(0)
  • 2020-11-28 22:19

    I have static UITableView and wanted to shift the margin of a cell separator to the left edge.

    Thanks to the above answers, this was my solution

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        // needed to shift the margin a specific cell to the left edge
        if indexPath.section == 3 && indexPath.row == 0 {
            cell.layoutMargins = UIEdgeInsetsZero
            cell.preservesSuperviewLayoutMargins = false
            cell.separatorInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)
        }
    }
    
    0 讨论(0)
  • 2020-11-28 22:19

    Just add the following:

    tableView.separatorStyle = .none
    
    0 讨论(0)
提交回复
热议问题