我在我的UIViewController中声明了这个插座并链接到故事板:
@IBOutlet var pennyView: UIView!
我在loadView中加载了一个PageView控制器并在按钮上设置了一个选项:
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]))
}
这一切都在iOS8模拟器中花花公子。但是我得到了一个"致命错误:在iOS7.1上运行时解开一个可选值" 引用此调用时意外发现nil
button.backgroundColor = UIColor.LightPurple(1)
是什么给出了?
答案 0 :(得分:1)
iOS 7.1和iOS 8.0之间最棘手问题的解决方案非常简单:
iOS模拟器>重置内容和设置
现在完美无缺,没有任何其他变化。疯狂。