登录后,情节提要在主控制器上返回nil

时间:2019-04-30 08:34:12

标签: ios swift user-interface uinavigationcontroller storyboard

我使用的是一个名为Main的故事板,当我尝试从登录屏幕重定向(推送)到主屏幕时,在ViewDidLoad的主屏幕上,我得到了self.storyboardnil,因此UI失真(视图,按钮,标签正在改变其位置)。我遇到这个问题的频率太高了,但是不是每次都遇到。

任何人都可以帮助我,将不胜感激。

3 个答案:

答案 0 :(得分:1)

let sb = UIStoryboard(name: "Main", bundle: nil)
let moveController = sb.instantiateViewController(withIdentifier: "StartViewController ") as! StartViewController 
self.navigationController?.pushViewController(moveController, animated: true)

答案 1 :(得分:1)

Please Check You have set both properly as i have done see image

请在code下尝试

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    if storyboard != nil{
           let VC = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
           self.navigationController?.pushViewController(VC, animated: true)
    }

希望,如果您不告诉我,就会得到解决方案

答案 2 :(得分:1)

尝试

let startViewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "StartViewController") as? StartViewController
self.navigationController?.pushViewController(startViewController!, animated: true)