UITableViewCell Separator disappearing in iOS7

前端 未结 30 774
轮回少年
轮回少年 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:28

    I dumped the subview hierarchy of affected cells and found that the _UITableViewCellSeparatorView was set to hidden. No wonder it's not shown!

    I overrode layoutSubviews in my UITableViewCell subclass and now the separators are displayed reliably:

    Objective-C:

    - (void)layoutSubviews {
        [super layoutSubviews];
    
        for (UIView *subview in self.contentView.superview.subviews) {
            if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
                subview.hidden = NO;
            }
        }
    }
    

    Swift:

    override func layoutSubviews() {
        super.layoutSubviews()
    
        guard let superview = contentView.superview else {
            return
        }
        for subview in superview.subviews {
            if String(subview.dynamicType).hasSuffix("SeparatorView") {
                subview.hidden = false
            }
        }
    }
    

    The other solutions proposed here didn't work consistently for me or seem clunky (adding custom 1 px footer views).

提交回复
热议问题