gpt4 book ai didi

ios - 在同一个标​​签栏项目上加载新的 viewController 不起作用

转载 作者:行者123 更新时间:2023-12-01 21:51:34 24 4
gpt4 key购买 nike

所以我在同一个标​​签栏项目上加载新的 View Controller 时遇到问题。我有一个标签栏 Controller 作为我的根 Controller ,标签栏上有 4 个标签。其中之一是帐户选项卡,当用户登录时,他需要查看其帐户详细信息的概述,但是当没有用户时,该选项卡栏项目上需要有一个登录/登录页面。目前,我有一个用于我的 tabbarcontroller 的自定义选项卡栏类,它具有我认为是解决方案但没有任何 react 的功能。我在需要加载的 View Controller (用户详细信息页面)中放置了一个断点,它出现在 ViewDidLoad 中,因此它加载但它没有出现在屏幕上。

希望我终于可以解决这个问题!

亲切的问候
B.

这是我的自定义标签栏 Controller 类:

import UIKit

class TabBarViewController: UITabBarController, UITabBarControllerDelegate {
var window: UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self

}


func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool{
let frame = UIScreen.main.bounds
window = UIWindow(frame: frame)
let index = tabBarController.viewControllers?.firstIndex(of: viewController)
if index == 3{ // Index of Account tab
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loginVC = mainStoryBoard.instantiateViewController(withIdentifier: "MessagesViewController") as! MessagesViewController
window?.rootViewController = loginVC
window?.makeKeyAndVisible()
}
return true// you decide
}
}


最佳答案

这是呈现全屏 loginVc 的代码

func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool{
let frame = UIScreen.main.bounds
window = UIWindow(frame: frame)
let index = tabBarController.viewControllers?.firstIndex(of: viewController)
if index == 1{ // Index of Account tab
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loginVC = mainStoryBoard.instantiateViewController(withIdentifier: "MessagesViewController") as! MessagesViewController
loginVC.modalPresentationStyle = .fullScreen
self.present(loginVC, animated: false, completion: nil)
}
return true// you decide
}

如果你还想有底栏......你的那个viewController应该是Navigation Controller,你可以推送你想要的ViewController然后喜欢
func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool{
let frame = UIScreen.main.bounds
window = UIWindow(frame: frame)
let index = tabBarController.viewControllers?.firstIndex(of: viewController)
if index == 1{ // Index of Account tab
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loginVC = mainStoryBoard.instantiateViewController(withIdentifier: "MessagesViewController") as! MessagesViewController
// loginVC.modalPresentationStyle = .fullScreen

if let navigation = viewController as? UINavigationController {

navigation.pushViewController(loginVC, animated: false)
}
}
return true// you decide
}

它将在顶部显示返回按钮和导航栏
如果你不想要 NavigationBar,那么在你的 MessagesViewController加载函数调用
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
// Do any additional setup after loading the view.
}

如果您只想隐藏后退按钮,请调用
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.setHidesBackButton(true, animated: false);
// Do any additional setup after loading the view.
}

关于ios - 在同一个标​​签栏项目上加载新的 viewController 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61565102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com