簡體   English   中英

崩潰:在viewController1上旋轉時約束在viewController2中為零

[英]Crash: constraint is nil in viewController2 while rotating on viewController1

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

    }

}

但是,如果在加載此視圖(viewController2)之前從另一個視圖旋轉應用程序,則會發生崩潰。 “在展開可選值時意外發現nil。” (tableViewConstraint)

我不明白為什么從另一個視圖調用此代碼(在viewController2中)。

有人有主意嗎? 謝謝,

如果不調用ViewController2就無法調用它,我復制了您的問題,並且正如預期的那樣, ViewController2內部什么都沒有調用

您必須有其他代碼來調用它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM