我正在子类化UITextField,以在左侧添加一个标签。我使用autolayout来布局标签。但是,我一直收到以下崩溃信息:
以下是我的布局代码:
当我不对文本字段进行任何调整时,这个工作正常。然而,如果我尝试设置占位符文本,我会得到这个异常:
以下是我的布局代码:
- (void)updateConstraints {
self.segmentLabel.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *constraint;
constraint = [NSLayoutConstraint constraintWithItem:self.segmentLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0f];
[self addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:self.segmentLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0f];
[self addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:self.segmentLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0f];
[self addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:self.segmentLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:self.segmentWidth];
[self addConstraint:constraint];
[super updateConstraints];
当我不对文本字段进行任何调整时,这个工作正常。然而,如果我尝试设置占位符文本,我会得到这个异常:
终止应用程序,由于未捕获的异常'NSInternalInconsistencyException',原因是:执行-layoutSubviews后仍需要自动布局。DDSegmentedTextField的-layoutSubviews实现需要调用super。但是,我没有覆盖-layoutSubviews。有人遇到过这个问题吗?我做错了什么?谢谢!