转换到另一个ViewController时获取黑屏

时间:2017-07-14 04:15:08

标签: ios swift transitions

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

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

enter image description here

3 个答案:

答案 0 :(得分:1)

从主故事板中将Storyboard ID提供给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)
    }

答案 1 :(得分: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 :(得分:0)

您只想尝试其他方式以编程方式显示目标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)