黑色的背景,SceneDelegate和第一视图

问题描述

我尝试将“视图”设置为第一视图并获得黑色背景。但是应该是红色的。 这是我的SceneDelegate:

import UIKit

class SceneDelegate: UIResponder,UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene,willConnectTo session: UIScenesession,options connectionoptions: UIScene.Connectionoptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard,the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingScenesession` instead).

        guard let _ = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        window?.rootViewController = MainNavigationController()
        
    }

这是我的MainNavigationController

import UIKit

class MainNavigationController: UINavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red
    }
}

解决方法

您只需要使用window初始化程序而不是windowScene初始化程序来声明frame

guard let windowScene = scene as? UIWindowScene else { return }
window = UIWindow(windowScene: windowScene)

注意:另外,如果以编程方式加载rootViewController,请确保禁用情节提要。

,

设置根目录后,您需要添加library(data.table) f_prev_n <- function(dat,colnm,n) { rowSums(sapply(data.table::shift(df[[colnm]],n = seq_len(n)),function(x) dat[[colnm]] == x),na.rm = TRUE) > 0 } df$previous_3 <- f_prev_n(df,'fruit',3) df$previous_3 #[1] FALSE FALSE FALSE FALSE TRUE TRUE FALSE TRUE df$previous_6 <- f_prev_n(df,6) df$previous_6 #[1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE 并将makeKeyAndVisible()分配给窗口...

window scene