UITableViewHeaderFooterView subclass with auto layout and section reloading won't work well together

后端 未结 11 1392
天涯浪人
天涯浪人 2020-12-30 23:04

I am trying to incorporate auto layout into my UITableViewHeaderFooterView subclass. The class is pretty basic, just two labels. This is the complete subclass:



        
11条回答
  •  自闭症患者
    2020-12-30 23:53

    In iOS 11 I just could not get UITableViewHeaderFooterView to display correctly.

    The problem was that I was setting my constraints when the UITableViewHeaderFooterView thought it's bounds were empty so it would always cause conflicts.

    Here's the solution

    override func layoutSubviews() {
        super.layoutSubviews()
        guard bounds != CGRect.zero else {
            return
        }
        makeConstraints()
    }
    

提交回复
热议问题