UITableViewCell Separator disappearing in iOS7

前端 未结 30 707
轮回少年
轮回少年 2020-12-07 08:31

I have some strange issue with UITableView only in iOS 7.

UITableViewCellSeparator disappears above the first row and below the last row. S

相关标签:
30条回答
  • 2020-12-07 09:03

    In your UITableViewCell Subclass implement layoutSubviews and add:

    - (void)layoutSubviews{
        [super layoutSubviews]
        for (UIView *subview in self.contentView.superview.subviews) {
            if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
                CGRect separatorFrame = subview.frame;
                separatorFrame.size.width = self.frame.size.width;
                subview.frame = separatorFrame;
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-07 09:04

    I also had the problem with missing separator and I found out that the problem only occured when heightForRowAtIndexPath was returning a decimal number. Solution:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return ceil(yourHeight) // Ceiling this value fixes disappearing separators
    }
    
    0 讨论(0)
  • 2020-12-07 09:04

    This fixed the issue for me:

    Make sure clipsToBounds is set to YES for the cell, but NO for the cell's contentView. Also set cell.contentView.backgroundColor = [UIColor clearColor];

    0 讨论(0)
  • 2020-12-07 09:04

    What made the difference for me was reloading the row for which the bottom separator line would not appear:

    NSIndexPath *indexPath = 
         [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];  
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    
    0 讨论(0)
  • 2020-12-07 09:07

    This worked for me:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        // fix for separators bug in iOS 7
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    
    0 讨论(0)
  • 2020-12-07 09:07

    You need to remove a cell selection before you doing cell's update. Then you could restore selection.

    NSIndexPath *selectedPath = [self.tableview indexPathForSelectedRow];
        [self.tableview deselectRowAtIndexPath:selectedPath animated:NO];
        [self.tableview reloadRowsAtIndexPaths:@[ path ] withRowAnimation:UITableViewRowAnimationNone];
        [self.tableview selectRowAtIndexPath:selectedPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    
    0 讨论(0)
提交回复
热议问题