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

后端 未结 11 1425
天涯浪人
天涯浪人 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:50

    I came upon this issue and the best solution I found is to set a default frame in the init. That frame will be changed anyway but it is useful for the constraints that would break on a 0,0,0,0 frame.

    override init(reuseIdentifier: String?) {
            super.init(reuseIdentifier: reuseIdentifier)        
            frame = CGRect(x: 0, y: 0, width: 100, height: 100)
    
            //... setup constraints...
    }
    

提交回复
热议问题