呈现问题 VC, 屏幕变黑
Problems with presenting VC, the screen turns black
我试图在用户登录后显示 VC。但登录成功后 VC 变黑。演示发生的事情是 here and there are same images. I have found articles here on Whosebug but any of them did not help me.enter image description here
试试这个代码:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: ALMainController = storyboard.instantiateViewController(withIdentifier: "ALMainController") as! ALMainController
self.present(vc, animated: true, completion: nil)
或者你可以使用这个:
let firstPage = self.storyboard?.instantiateViewController(withIdentifier: "ALMainController")as! ALMainController
let appDelegate = UIApplication.shared.delegate
appDelegate?.window??.rootViewController = firstPage
两者都应该有效。
并且不要忘记将:"ALMainController" 写入您的故事板 ID。
让我知道它是否有效。 :)
所以问题是您只是在初始化 ALMainController class。
但是,这不会从情节提要中加载您的视图。有两种方法可以正确地做到这一点并显示该控制器。
- 在代码中执行如下操作,假设此控制器具有如下标识符:"ALMainController"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
让控制器 = storyboard.instantiateViewController(withIdentifier: "ALMainController")<br>
self.present(控制器,动画:真,完成:无)
- 通过在故事板中创建从 "Login controller" 走向 "ALMainController" 的 Segue。你给那个 segue 一个标识符(例如:"goToMain")并在你的代码中调用它做类似下面的事情
self.performSegue(withIdentifier: "goToMain", sender: self)
希望对您有所帮助!
我试图在用户登录后显示 VC。但登录成功后 VC 变黑。演示发生的事情是 here and there are same images. I have found articles here on Whosebug but any of them did not help me.enter image description here
试试这个代码:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: ALMainController = storyboard.instantiateViewController(withIdentifier: "ALMainController") as! ALMainController
self.present(vc, animated: true, completion: nil)
或者你可以使用这个:
let firstPage = self.storyboard?.instantiateViewController(withIdentifier: "ALMainController")as! ALMainController
let appDelegate = UIApplication.shared.delegate
appDelegate?.window??.rootViewController = firstPage
两者都应该有效。
并且不要忘记将:"ALMainController" 写入您的故事板 ID。
让我知道它是否有效。 :)
所以问题是您只是在初始化 ALMainController class。
但是,这不会从情节提要中加载您的视图。有两种方法可以正确地做到这一点并显示该控制器。
- 在代码中执行如下操作,假设此控制器具有如下标识符:"ALMainController"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
让控制器 = storyboard.instantiateViewController(withIdentifier: "ALMainController")<br>
self.present(控制器,动画:真,完成:无)
- 通过在故事板中创建从 "Login controller" 走向 "ALMainController" 的 Segue。你给那个 segue 一个标识符(例如:"goToMain")并在你的代码中调用它做类似下面的事情
self.performSegue(withIdentifier: "goToMain", sender: self)
希望对您有所帮助!