我在 viewController2 中调用此代码:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
rotatedBool = true
tableViewConstraint.constant = -12
} else {
rotatedBool = false
tableViewConstraint.constant = 21
}
}
但是,如果我在加载此 View (viewController2) 之前从另一个 View 旋转应用程序,则会崩溃。 “在展开可选值时意外发现 nil。” ( TableView 约束)
我不明白为什么从另一个 View 调用此代码(在 viewController2 中)。
有人有想法吗? 谢谢,
最佳答案
如果不调用ViewController2
就无法调用它我复制了您的问题,并且正如预期的那样,ViewController2
内部没有调用任何内容
您必须有其他代码调用它
关于ios - 崩溃: constraint is nil in viewController2 while rotating on viewController1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32933102/