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

后端 未结 11 1423
天涯浪人
天涯浪人 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条回答
  •  猫巷女王i
    2020-12-31 00:04

    I had a similar problem with just one extra label in the contentView. Try to insert

    static void MBTableDetailStyleFooterViewCommonSetup(MBTableDetailStyleFooterView *_self) {
        _self.contentView.translatesAutoresizingMaskIntoConstraints = NO
        [...]
    }
    

    at first line in your MBTableDetailStyleFooterViewCommonSetup function. For me, this works in conjunction with reloadSections:withRowAnimations:.

    Update:

    I also added a new constraint for the contentView to use all width:

    NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|"
                                                                              options:0
                                                                              metrics:nil
                                                                                views:@{@"contentView" : _self.contentView}];
    [_self.contentView.superview addConstraints:horizontalConstraints];
    

提交回复
热议问题