Swift -从StoryBoard重定向到另一个

xienkqul  于 2024-01-05  发布在  Swift
关注(0)|答案(1)|浏览(165)

“开始这个项目时,我想在拥有视图时保持整洁,所以我做了一个故事板,在那里我有我的登录视图和一个有家的故事板,也就是说,我不把Main作为故事板。
当我从sceneDelegate启动应用程序时,我可以知道我是否登录了,因为我在我的UserController中保存了相应的标志,所以这就是我如何使用其各自的UIViewController创建一个故事板或另一个故事板的方式。
我的问题是当我做登录本身,因为在这一点上,我想重定向到homeStoryBoard,它使用HomeUIViewController.通过有这些视图分开组织,我没有找到一种方法去该视图没有返回登录的可能性,因为我已经登录.我发现的方式,提高了从家里的看法,如果它是一个弹出窗口,但这不会为我工作。
我来做一个新的项目,在那里我使用了一个单一的故事板主,并有我的意见,但与此解决方案的问题,我看到的是,“返回”按钮是产生的,这将使我从主页返回到登录,这不会帮助我。
我在我的场景委托中做了下一个代码.

  1. func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  2. if let _ = UserDefaults.standard.string(forKey: kIsLogged) {
  3. print("I'm loggin")
  4. guard let windowScene = (scene as? UIWindowScene) else { return }
  5. window = UIWindow(frame: windowScene.coordinateSpace.bounds)
  6. window?.windowScene = windowScene
  7. window?.makeKeyAndVisible()
  8. let storyboard = UIStoryboard(name: "ServiceHomeViewStoryBoard", bundle: nil)
  9. window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "SB_ServiceHome")
  10. } else {
  11. print("I'm not loggin")
  12. guard let windowScene = (scene as? UIWindowScene) else { return }
  13. window = UIWindow(frame: windowScene.coordinateSpace.bounds)
  14. window?.windowScene = windowScene
  15. window?.makeKeyAndVisible()
  16. let storyboard = UIStoryboard(name: "LogIn", bundle: nil)
  17. window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "LogInStoryBoard")
  18. }
  19. }

字符串
在我的LooginViewController我登录后功能成功.

  1. let storyBoard = UIStoryboard(name: "ServiceHomeViewStoryBoard", bundle: nil)
  2. let serviceHomeViewController = storyBoard.instantiateViewController(withIdentifier: "SB_ServiceHome")
  3. self.navigationController?.pushViewController(serviceHomeViewController, animated: true)
  4. self.navigationController?.present(serviceHomeViewController, animated: true)
  5. self.present(serviceHomeViewController, animated:true, completion:nil)


The second view appears as a modal

92vpleto

92vpleto1#

我认为你需要设置根视图控制器,而移动到家庭控制器.这里我有scenedelegate的扩展,你可以根视图控制器.

分机号

在此Extension设置导航栏isNavigationBarHidden根据您的要求设置。

  1. extension SceneDelegate {
  2. func setRootViewController(controller:UIViewController) {
  3. let navigationController = UINavigationController(rootViewController: controller)
  4. navigationController.isNavigationBarHidden = true
  5. self.window?.rootViewController = navigationController
  6. self.window?.makeKeyAndVisible()
  7. }
  8. }

字符串

如何使用

  1. guard let scene = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate else {return}
  2. let storyBoard = UIStoryboard(name: "YOUR_STORYBOARD_NAME", bundle: nil)
  3. guard let vc = storyBoard.instantiateViewController(withIdentifier: "YOUR_CONTROLLER_IDENTIFIER") as? YOUR_CONTROLLER_NAME_CLASS else {return}
  4. scene.setRootViewController(controller: vc)

展开查看全部

相关问题