I have this outlet declared in my UIViewController and linked to the storyboard:
@IBOutlet var pennyView: UIView!
I'm loading a PageView Controller in loadView and setting an option on the button:
override func loadView() {
super.loadView()
//Add PageViewController
pageViewController = UIPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation:
UIPageViewControllerNavigationOrientation.Horizontal, options: nil)
let child = viewControllerAtIndex(0)
pageViewController!.setViewControllers([child!], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
pageViewController!.dataSource = self
self.addChildViewController(pageViewController!)
self.view.addSubview(pageViewController!.view)
//Add Buttom
button.backgroundColor = UIColor.LightPurple(1)
let pageViewcontrollerView = pageViewController!.view
pageViewcontrollerView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[pageViewcontrollerView][button]", options: nil, metrics: nil, views: ["pageViewcontrollerView":pageViewcontrollerView, "button":button]))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[pageViewcontrollerView]|", options: nil, metrics: nil, views: ["pageViewcontrollerView":pageViewcontrollerView, "button":button]))
}
This all works dandy in iOS8 simulator. But I get a "fatal error: unexpectedly found nil while unwrapping an Optional value" referencing this call while running on iOS7.1
button.backgroundColor = UIColor.LightPurple(1)
What gives?