-1

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?

zooster
  • 352
  • 3
  • 8
  • I'm assuming you've defined an extension of `UIColor` with `class func LightPurple()`? This isn't a standard function of `UIColor` - can you show us your implementation of this method? – Craig Otis Oct 03 '14 at 14:27
  • Yes I have. Again, it works in ios8, not below. Error persists if I don't use the UIColor extension. In fact, it happens with any call to button. `import Foundation import UIKit extension UIColor { class func LightPurple(alpha: CGFloat) -> UIColor { return UIColor(red: 174/255, green: 168/255, blue: 211/255, alpha: alpha) } }` Not sure why this was downvoted? If the original question is stupid because of 'x', let me know what 'x' is. – zooster Oct 03 '14 at 16:20

1 Answers1

1

The solution to this most vexing problem between iOS 7.1 and iOS 8.0 was as simple as:

iOS Simulator > Reset Content and Settings

It works perfectly now without any other changes. Craziness.

zooster
  • 352
  • 3
  • 8