Reputation: 3234
i added this piece of code in viewdidload method to Add the Vertical Space Constraint to the top-most view
as based on apple Technical Q&A QA1797 Preventing the Status Bar from Covering Your Views
[NSLayoutConstraint constraintWithItem:self.toolbar1
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.topLayoutGuide
attribute:NSLayoutAttributeBaseline
multiplier:1.0
constant:0.0];
but it crashes app and shows this error NSInvalidArgumentException', reason: '[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint must contain a first layout item'
Any clues why i m getting this error and how this can be fixed.
Thanks for help.
Upvotes: 1
Views: 5522
Reputation: 779
This happens when you are setting up UI code in your init method, when your views are not created yet. Try moving your code to the viewDidLoad method and see if it works.
Upvotes: 1
Reputation: 1283
This error occurs if both items are nil. Most likely your first item 'self.toolbar1' is nil.
Upvotes: 4