gpt4 book ai didi

ios - 在 tabitem 单击时以编程方式加载 navigationController

转载 作者:行者123 更新时间:2023-11-30 11:05:07 26 4
gpt4 key购买 nike

我制作了一个 UITabBarController,当选择其中一个项目时,我加载一个图像选择器。现在,在用户从选择器中选择图像后,我想加载一个导航 Controller ,但我无法加载。我的代码是

extension BaseTabBarController : UITabBarControllerDelegate {

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if self.viewControllers?.index(of:viewController) == 2 {
// Presenting image picker here
present(self.imagePicker, animated: true, completion: nil)
return false
} else {
return true
}
}

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {

}

}

这是用户选择图像后的代码

extension BaseTabBarController : ImagePickerDelegate {

func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {

//This is the StoryboardID of Navigationcontroller i want to goto
let detailVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "UploadNavigationController")
//This is not working
present(detailVC, animated: true,completion: nil)
}
}

此处未显示 Controller ,我收到此警告

Warning: Attempt to present <UINavigationController: 0x7fb4969c4800> on <BaseTabBarController: 0x7fb49780ea00> whose view is not in the window hierarchy!

我想显示导航 Controller ,标签栏在底部仍然可见

最佳答案

我想,当您想要显示导航 Controller 时,标签栏在底部仍然可见,那么您应该首先关闭图像选择器,然后推送不存在的新 Controller 。

因为如果您呈现任何 Controller 都会覆盖整个屏幕,因为它是从根 Controller 呈现的。如果您按下,它将从当前 Controller 按下,并且 tabor 保持原样。

extension BaseTabBarController : ImagePickerDelegate {

func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
self.imagePicker.dismiss(animated: true) {
//This is the StoryboardID of Navigationcontroller i want to goto
let detailVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "UploadNavigationController")
//This is not working
let nav = UINavigationController(rootViewController: detailVC)
navigationController?.pushViewController(nav, animated: true)
//present(detailVC, animated: true,completion: nil)
}
}

关于ios - 在 tabitem 单击时以编程方式加载 navigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52815007/

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