Reputation: 1055
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]))
}
Upvotes: 0
Views: 129
Reputation: 1055
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.
Upvotes: 1