UITableViewCell Separator disappearing in iOS7

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

    Based on @ortwin-gentz's comment, this solution works for me in iOS 9.

    func fixCellsSeparator() {
    
        // Loop through every cell in the tableview
        for cell: UITableViewCell in self.tableView.visibleCells {
    
            // Loop through every subview in the cell which its class is kind of SeparatorView
            for subview: UIView in (cell.contentView.superview?.subviews)!
                where NSStringFromClass(subview.classForCoder).hasSuffix("SeparatorView") {
                    subview.hidden = false
            }
        }
    
    }
    

    (Swift code)

    I use fixCellsSeparator() function after calling endUpdates() in some methods of my tableView, for example:

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
        //  Perform some stuff
        //  ...
    
        self.tableView.endUpdates()
        self.fixCellsSeparator()
    
    }
    

    I hope this solution will be helpfull for someone!

提交回复
热议问题