in Education by
When I'm extending my UIViewController and calling the extended ViewController I'm getting : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for (null): Constraint must contain a first layout item' error. CGSize size = CGSizeMake(142, 200); [self.scrollView.subviews enumerateObjectsUsingBlock:^(UIView* subView, NSUInteger i, BOOL *stop) { subView.translatesAutoresizingMaskIntoConstraints = NO; [ViewHelper addWidthConstraint:subView width:size.width]; [ViewHelper addHeightConstraint:subView height:size.height]; if (i < self.scrollView.subviews.count - 1) { [ViewHelper addHorizontalConstraint:self.scrollView previouseView:subView nextView:(UIView*)self.scrollView.subviews[i + 1] spacer:8]; } [ViewHelper addEdgeConstraint:NSLayoutAttributeTop superview:self.scrollView subview:subView]; [ViewHelper addEdgeConstraint:NSLayoutAttributeBottom superview:self.scrollView subview:subView]; }]; [ViewHelper addEdgeConstraint:NSLayoutAttributeLeft superview:self.scrollView subview:self.scrollView.subviews.firstObject]; [ViewHelper addEdgeConstraint:NSLayoutAttributeRight superview:self.scrollView subview:self.scrollView.subviews.lastObject]; [ViewHelper addHeightConstraint:self.scrollView height:size.height]; Crashing at this line: [ViewHelper addEdgeConstraint:NSLayoutAttributeLeft superview:self.scrollView subview:self.scrollView.subviews.firstObject]; JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The error indicates that you're attempting to add a constraint using a view which is nil. You should guard against one the self.scrollView.subviews.firstObject/lastObject being nil before attempt to add the constraints to them (by making sure the scrollView has any subviews). Here's an example: // make sure that the scrollView has some subviews before attempting to add layout constraints using the subviews if ([self.scrollView.subviews count] > 0) { [ViewHelper addEdgeConstraint:NSLayoutAttributeLeft superview:self.scrollView subview:self.scrollView.subviews.firstObject]; [ViewHelper addEdgeConstraint:NSLayoutAttributeRight superview:self.scrollView subview:self.scrollView.subviews.lastObject]; }

Related questions

0 votes
    Select * from OPENQUERY (PORTAL, ''SELECT st.last AS "Last Name", st.first AS "First Name", ct. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    How do I see which version of Swift I'm using?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is ... for unary +: 'str' Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I wrote javascript code to solve the following problem >>> Write a function exponentiate that accepts two ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    In Javascript, I can do something like this let list = [1, 2, 3] let list2 = [4, 5, 6, ...list] And ... the += after declaring a list? Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    When a class B can extend another class A, we say that? (a) A is the superclass and B is the ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    import os import sys import fileinput print ("Text to search for:") textToSearch = input( "> " ) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    After reading up on some options (sqlite, derby etc...), I've decided to throw down with HSQLDB. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
...