调用insertSections:withRowAnimation:endUpdates后出现以下错误。该错误与我的自定义UITableViewHeaderFooterView中的自动布局有关,但仅在dequeueReusableHeaderFooterViewWithIdentifier:重用标头时才出现。第一次运行正常,没有错误。

Unable to simultaneously satisfy constraints.
...
(
    "<NSLayoutConstraint:0x10b77f9f0 V:|-(8)-[UIView:0x10b77d0f0]   (Names: '|':WYBDetailHeaderView:0x10b77e620 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x10b77cac0 h=--& v=--& V:[WYBDetailHeaderView:0x10b77e620(0)]>",
    "<NSLayoutConstraint:0x10b77fa40 V:[UIView:0x10b77d0f0]-(>=4)-|   (Names: '|':WYBDetailHeaderView:0x10b77e620 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10b77fa40 V:[UIView:0x10b77d0f0]-(>=4)-|   (Names: '|':WYBDetailHeaderView:0x10b77e620 )>

水平约束存在类似的误差。问题是宽度和高度都设置为零时会出现NSAutoresizingMaskLayoutConstraint。但是,一旦动画完成,标题布局就正确且看起来不错。

我遵循了这个相关问题中的建议,但没有运气:UITableViewHeaderFooterView subclass with auto layout and section reloading won't work well together

有人遇到过类似的事情吗?

有什么我可以避免该警告的措施吗?

这是我的UITableView中的实现:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    WYBDetailHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"WYB"];
    [header setupWithTitle:@"Title" subtitle:@"Subtitle"];
    return header;
}

和WYBDetailHeaderView的实现(它使用我向registerNib:forHeaderFooterViewReuseIdentifier:注册的NIB):
- (void)setupWithTitle:(NSString *)title subtitle:(NSString *)subtitle
{
    // Set labels.
    self.titleLabel.text = title.uppercaseString;
    self.subtitleLabel.text = subtitle;

    // Clear image.
    self.headerImageView.image = nil;
    self.emptyImage = NO;

    // Mark for layout update.
    [self setNeedsUpdateConstraints];
    [self setNeedsLayout];
}

- (void)prepareForReuse
{
    self.prototype = NO;
    self.emptyImage = NO;
}

- (void)updateConstraints
{
    // See if there is an image.
    if (self.emptyImage || self.headerImageView.image) {
        self.imageWidthConstraint.constant = 20;
        self.imageHeightConstraint.constant = 20;
        self.imageTitleSpaceConstraint.constant = 8;
    }
    else {
        self.imageWidthConstraint.constant = 0;
        self.imageHeightConstraint.constant = 0;
        self.imageTitleSpaceConstraint.constant = 0;
    }

    [super updateConstraints];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.titleLabel.frame);
    self.subtitleLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.subtitleLabel.frame);
    [super layoutSubviews];
}

最佳答案

我只是遇到了类似的错误,并使用了EstimatedHeightForRowAtIndexPath导致了它。

关于ios - 重复使用UITableViewHeaderFooterView时出现NSAutoresizingMaskLayoutConstraint错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23253533/

10-14 21:13
查看更多