Я добавляю NSContraints на панель инструментов UINavigationController
и получаю эту ошибку:
Невозможно изменить ограничения для UIToolbar
, управляемого UINavigationController
In ViewDidLoad:
self.navigationController.toolbarHidden = NO;
[self.navigationController.toolbar addSubview:_labelName];
[self.navigationController.toolbar addSubview:_labelAddress];
Затем я вызываю метод ниже:
NSLayoutConstraint *nameRight = [NSLayoutConstraint constraintWithItem:_labelName attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeRight multiplier:1 constant:20];
NSLayoutConstraint *nameLeft = [NSLayoutConstraint constraintWithItem:_labelName attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeLeft multiplier:1 constant:20];
NSLayoutConstraint *nameTop = [NSLayoutConstraint constraintWithItem:_labelName attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeTop multiplier:1 constant:0];
NSLayoutConstraint *nameHeight = [NSLayoutConstraint constraintWithItem:_labelName attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeHeight multiplier:.5 constant:0];
NSLayoutConstraint *addressRight = [NSLayoutConstraint constraintWithItem:_labelAddress attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeRight multiplier:1 constant:20];
NSLayoutConstraint *addressLeft = [NSLayoutConstraint constraintWithItem:_labelAddress attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeLeft multiplier:1 constant:20];
NSLayoutConstraint *addressTop = [NSLayoutConstraint constraintWithItem:_labelAddress attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_labelName attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
NSLayoutConstraint *addressHeight = [NSLayoutConstraint constraintWithItem:_labelAddress attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.navigationController.toolbar attribute:NSLayoutAttributeHeight multiplier:.5 constant:0];
[self.navigationController.toolbar addConstraints:@[nameRight, nameLeft, nameTop, nameHeight, addressRight, addressLeft, addressTop, addressHeight]];
Должен ли я создать UIView
на панели инструментов контроллера навигации? и положить внутрь ограничения?