我们正在设计一个ios应用程序,我们遇到tabbar问题。
我们有一些页面没有显示在tabbar中。用户只有在点击页面中的按钮时才能访问这些页面。因此,我们没有将它们连接到tabbar。
如果用户打开应用并单击按钮,则会正确显示这些页面中的标签栏。这就是我想要的,每个页面都应显示标签栏。
但是,如果用户点击共享链接,例如" myApp:// pageToShow"我直接从app delegate推送用户到这个页面,tabbar没有显示。由于页面不属于tabbar,因此我无法使用索引显示tabbar。
以下是我在app delegate中的源代码:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let ID: String = (String(describing: url)).replacingOccurrences(of: "myApp131774217473267://", with: "")
print(ID)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
var nextView = storyboard.instantiateViewController(withIdentifier: "RestStory") as? RestViewController
nextView?.mainToRestInfo = ID
let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "RestStoryNavbar") as! UINavigationController
window?.rootViewController = firstNavigationController
firstNavigationController.pushViewController(nextView as! RestViewController, animated: true)
return true
}
你有什么建议吗?
答案 0 :(得分:0)
这个问题的答案取决于太多的事情,甚至把它放在评论中:
无论如何,最好的方法是检查你是否有一个当前的导航控制器并将新的控制器推向它。这假定(1)为真,(2)为真,(3)准备处理从中导航:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let ID: String = (String(describing: url)).replacingOccurrences(of: "myApp131774217473267://", with: "")
print(ID)
guard let viewControllerToShow = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RestStory") as? RestViewController else {
return false
}
viewControllerToShow.mainToRestInfo = ID
if let currentNavigationController = self.navigationController {
currentNavigationController.pushViewController(viewControllerToShow, animated: true)
} else {
let navigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RestStoryNavbar") as? UINavigationController ?? UINavigationController()
window?.rootViewController = navigationController
navigationController.pushViewController(viewControllerToShow, animated: true)
}
return true
}
如果不是这种情况,那么我想让3分有效。如果这不是一个选项,那么仍有embedding a view controller的可能性。但要这样做,那么(2)必须是假的,甚至标签栏也不能在导航控制器的层次结构中,导航控制器有一个可见的导航栏可以工作......
您发布的代码在您的导航架构中看起来相当大,所以我希望您从中学到一些东西。