ios - 崩溃: constraint is nil in viewController2 while rotating on viewController1

标签 ios swift rotation viewcontroller

我在 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/

相关文章:

ios - ios如何旋转控制360度

ios - 为什么在使用 CGAffineTransform MakeRotation 旋转时 View 会改变位置

ios - 无效的包 - 嵌套包没有在 CFBundleSupportedPlatforms Info.plist 键中列出的正确平台

ios - 杀死一个用 dispatch_sync 锁定的线程

ios - 导航栏中的 UITextField

ios - 在 swift 4 中比较 Day from Date 的问题

ios - Twilio iOS SDK 在去电时失败并显示 "400 Bad request"

swift - 如何运行 AsyncTask 从服务器返回响应,然后继续到下一个 View Controller

java - 改进旋转文本的显示

ios - 获取长按时在 UIScrollView 中添加的 UIButtons 的标签