微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从SceneDelegate加载视图时出现黑屏

如何解决从SceneDelegate加载视图时出现黑屏

当我尝试加载此视图时,屏幕几乎黑屏。但是,如果我添加 view.backgroundColor = .red ,它将正确显示红色。只是我在情节提要中所做的设置不会显示

Image

这是我使用的代码

import UIKit

class SceneDelegate: UIResponder,UIWindowSceneDelegate {

    var window: UIWindow?


     func scene(_ scene: UIScene,willConnectTo session: UIScenesession,options connectionoptions: UIScene.Connectionoptions) {
   
    guard let _ = (scene as? UIWindowScene) else { return }

    
    
    guard let windowScene = scene as? UIWindowScene else { return }
    window = UIWindow(windowScene: windowScene)
    let mainStoryboard = UIStoryboard(name: "Main",bundle: nil)
    window?.rootViewController = mainStoryboard.instantiateViewController(withIdentifier: "ResultsViewController") as! ResultsViewController
    window?.makeKeyAndVisible()

    
}


import UIKit

class ResultsViewController: UINavigationController {

   
    override func viewDidLoad() {
          
        super.viewDidLoad()
        
view.backgroundColor = .blue
        
    }
    

}

解决方法

您似乎已在情节提要中创建了diff_y[y_actual[:,]> 0 and y_predicted[:,0] <0] *=2。您必须从情节提要中加载它,才能将其设置为ResultsViewController

rootViewController

注意:不要忘记在情节提要中将let mainStoryboard = UIStoryboard(name: "Main",bundle: nil) window?.rootViewController = mainStoryboard.instantiateViewController(withIdentifier: "ResultsViewController") as! ResultsViewController 的标识符设置为“ ResultsViewController”。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。