【问题标题】:Entrypoint is not changing入口点没有改变
【发布时间】:2022-12-10 10:05:32
【问题描述】:

我是 Swift 和 Xcode 的新手,我在网上找不到答案,所以我希望你们能帮助我。

我正在尝试在有人登录时更改屏幕。我正在尝试将默认入口点更改为另一个屏幕,但不知何故它不起作用。

这是在我试图更改入口点的 AppDelegate 中:

var window: UIWindow?
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let mainStoryboard = UIStoryboard(name: "Main" , bundle: nil)
    let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "homePage") as! HomePageController
    window?.rootViewController = initialViewController
    window?.makeKeyAndVisible()
    return true
}

在这里,我为要替换为默认入口点的屏幕/控制器设置了 ID(默认入口点是我的登录屏幕)。

【问题讨论】:

  • 这回答了你的问题了吗? set initial viewcontroller in appdelegate - swift
  • @stackich 我已经试过了,但我的登录页面仍然是入口集。我的页面没有变到首页
  • 从你的问题中不清楚你所说的 entry point 是什么意思,你的 VC 是在哪里创建的,以及你是否使用故事板(特别是两个 VC 的一个故事板)

标签: ios swift storyboard


【解决方案1】:

尝试在 sceneDelegate 中这样做:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowsScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(windowScene: windowsScene)
    window?.makeKeyAndVisible()
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "homePage") as! HomePageController
    window?.rootViewController = initialViewController
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    相关资源
    最近更新 更多