提问人:vonnov 提问时间:8/16/2023 最后编辑:vonnov 更新时间:8/16/2023 访问量:27
无法在 TabBarController 的“更多”选项卡中推送视图控制器
Fail to Push View Controller in "More" Tab in TabBarController
问:
我已经设置了 6 个视图控制器(位于 TabBar 的“更多”选项卡中):serviceVC
facebookVC
@available(iOS 13.0, *)
private func setupTabs(){
let home = self.createNav(with: "home", and: UIImage(systemName: "house"), vc: HomeVC())
let unit = self.createNav(with: "unit", and: UIImage(systemName: "mappin.and.ellipse"), vc: UnitVC())
let donate = self.createNav(with: "donate", and: UIImage(systemName: "heart.circle"), vc: DonateVC())
let infopage = self.createNav(with: "About us", and: UIImage(systemName: "newspaper"), vc: InfoVC())
let facebookpage = self.createNav(with: "Facebook", and: UIImage(named: "facebookIcon.png"), vc: FacebookVC())
let service = self.createNav(with: "service", and: UIImage(systemName: "info.circle"), vc: ServiceVC())
self.setViewControllers([home,infopage,unit,donate,service,facebookpage], animated: true)
}
然后在函数中,它调用以下函数(我可以成功调用它,因为所有 6 个视图控制器中都打印了“pressed”):createNav
handleButtonTap
@available(iOS 13.0, *)
private func createNav(with title: String, and image: UIImage?, vc: UIViewController) -> UINavigationController{
let nav = UINavigationController(rootViewController: vc)
nav.tabBarItem.title = title
nav.tabBarItem.image = image
nav.viewControllers.first?.navigationItem.title = ""
nav.viewControllers.first?.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "list.bullet"), style: .plain, target: self, action: #selector(handleButtonTap))
return nav
}
@available(iOS 13.0, *)
@objc private func handleButtonTap(){
print("pressed")
guard let selectedNavController = self.selectedViewController as? UINavigationController else{return}
let vc = MenuViewController()
selectedNavController.pushViewController(vc, animated: true)
}
但是,在 和 中,它无法推送 .有什么想法吗?serviceVC
facebookVC
MenuViewController()
我绑住了将 和 移动到前面 ( ),然后无法推送新的视图控制器。我猜问题发生在 TabBar 的“更多”选项卡中?serviceVC
facebookVC
self.setViewControllers([service,facebookpage,home,infopage,unit,donate], animated: true)
unitVC
donateVC
答: 暂无答案
评论
createNav
guard
handleButtonTap
print
guard
nav.viewControllers.first?.navigationItem.title = ""
vc.navigationItem.title = ""
nav.viewControllers.first?.navigationItem.rightBarButtonItem = UIBarButtonItem...
vc.navigationItem.rightBarButtonItem = UIBarButtonItem...