0

I am trying to have add a view inside a paging-scrollView inside of a ViewController, and I am having a lot of Auto Layout problems (all of this code is programatic, non-Storyboard).

The first set of constraints work properly, but the second set (sv and firstView) cause the following error: libc++abi.dylib: terminating with uncaught exception of type NSException

Any help on this issue would be greatly appreciated, code below:

override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .whiteColor()

    sv.backgroundColor = .redColor()
    view.addSubview(sv)

    sv.translatesAutoresizingMaskIntoConstraints = false
    view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[sv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["sv": sv]))
    view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[sv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["sv": sv]))
    sv.pagingEnabled = true

    let firstView = UIView()
    firstView.backgroundColor = .greenColor()
    sv.addSubview(firstView)
    firstView.translatesAutoresizingMaskIntoConstraints = false
    sv.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[f]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["fv": firstView]))
    sv.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[fv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["fv": firstView]))
}
2
  • 1
    You have "[f]" instead of "[fv]" in one of your visual formats Commented Jun 24, 2016 at 22:31
  • wow, that was it! Thanks so much. Amazing that the debugging can't tell me that... Commented Jun 24, 2016 at 22:33

1 Answer 1

1

As @dan pointed out, there is a typo in the string in the visual format. I'll leave this post up in case anyone happens to run into a similar issue. The take-away:

terminating with uncaught exception of type NSException with Auto Layout might be caused by typos in the visual strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.