【问题标题】:Getting black screen while transition to another ViewController过渡到另一个 ViewController 时出现黑屏
【发布时间】:2017-07-14 04:15:08
【问题描述】:

我正在尝试转换到另一个 ViewController,但它给了我黑屏!有我的代码:

                            if (content == nil) {
                            let sec: testViewController = testViewController(nibName: nil, bundle: nil)
                            self.present(sec, animated: true, completion: nil)
                        }

在故事板中:

【问题讨论】:

  • 另外,你的类名应该以 Cap Later 开头,testViewController 应该是 TestViewController
  • @MikeAlter 我想没关系
  • 我知道这不是答案,我只是告诉你标准

标签: ios swift transitions


【解决方案1】:

在 Storborad 中给出故事板 ID ex-->testViewControllerId 并检查 UseStoryboard Id

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let testController = storyboard.instantiateViewController(withIdentifier :"testViewControllerId") as! testViewController
self.present(testController, animated: true)

【讨论】:

    【解决方案2】:

    将 Storyboard ID 从 Main Storyboard 提供给 testViewController。

    if content == nil {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let sec: testViewController = storyboard.instantiateViewController(withIdentifier: "testViewController") as! testViewController
        self.present(sec, animated: true, completion: nil)
        }
    

    【讨论】:

      【解决方案3】:

      您只是想尝试另一种方式以编程方式呈现您的目标 ViewController。试试这个,

      let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
      let myViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("<myViewControllerRestorationID>") //if you have the restoration ID, otherwise use 'ModalViewController'
      self.presentViewController(myViewController, animated: true, completion: nil)
      

      【讨论】:

      • 现在它给出了错误我也以这种方式尝试了错误:libc++abi.dylib: terminating with uncaught exception of type NSException
      猜你喜欢
      • 2014-05-03
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多