I have an IBOutlet NSLayoutConstraint in my app. Very simple:
@property (nonatomic, weak) IBOutlet NSLayoutConstraint* leftConstraint; At some point I want to deactivate this constraint:
self.leftConstraint.active = NO; It happens in a method called from cellForRowAtIndexPath:. And the constraint becomes nil right after the line above. However if I declare this property as strong then it's ok, it doesn't turn to nil. Can anybody explain why it happens?
When your outlet is weak, the only strong reference is from the view's constraints property. Deactivating the constraint removes it from that array, so there are no more strong references.
A possible workaround would be to change the constraint priority instead of making it inactive:
@property (nonatomic, weak) IBOutlet NSLayoutConstraint* leftConstraint; (...) self.leftConstraint.priority = 250; Then, self.leftConstraint is not disposed.
EDIT:
Xcode does not support changing priority for required (=1000) constraints, so be sure you switch in a range between 1...999.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With