iOS 8 UITableView separator inset 0 not working

前端 未结 30 1443
清酒与你
清酒与你 2020-11-22 14:38

I have an app where the UITableView\'s separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.

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

    Arg!!! After playing around either doing this in your Cell subclass:

    - (UIEdgeInsets)layoutMargins
    {
        return UIEdgeInsetsZero;
    }
    

    or setting the cell.layoutMargins = UIEdgeInsetsZero; fixed it for me.

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

    Just add below code can solve this program.

    Good luck to you!

    -(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];
           }
    
    }
    
    0 讨论(0)
  • 2020-11-22 15:18

    This worked perfectly for me in iOS 8 and iOS 9.

    For OBJ-C

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(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];
            }
             return cell;
        }
    
    0 讨论(0)
  • 2020-11-22 15:19

    Use below code snippet avoid unwanted padding issue for UITableView in IOS 8 & 7.

    -(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];
        }
    }
    
    0 讨论(0)
  • 2020-11-22 15:20

    I made it work by doing this:

    tableView.separatorInset = UIEdgeInsetsZero;
    tableView.layoutMargins = UIEdgeInsetsZero;
    cell.layoutMargins = UIEdgeInsetsZero;
    
    0 讨论(0)
  • 2020-11-22 15:22

    Instead of updating preservesSuperviewLayoutMargins and layoutMargins every time the cell scrolls in (using willDisplayCell), I'd suggest to do it once in cellForRowAtIndexPath::

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
        let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
    
        cell.preservesSuperviewLayoutMargins = false
        cell.layoutMargins = UIEdgeInsetsZero
    
        return cell
    
    }
    
    0 讨论(0)
提交回复
热议问题