[英]How to remove/replace tabBar items in UITabbarController subclass in Swift?
[英]How to show UITabBarController in the pages which are not belong to tabbar in swift 4?
我們正在設計一個ios應用程序,並且選項卡欄有問題。
我們有些頁面沒有顯示在選項卡中。 用戶只有在單擊頁面中的按鈕時才能訪問這些頁面。 因此,我們沒有將它們連接到標簽欄。
如果用戶打開應用程序並單擊按鈕,則選項卡欄將正確顯示在這些頁面中。 這就是我想要的,應該在每個頁面中顯示標簽欄。
但是,如果用戶單擊共享鏈接(例如“ myApp:// pageToShow”)並且我直接將用戶從應用程序委托推送到此頁面,則不會顯示選項卡。 由於頁面不屬於標簽欄,因此無法顯示帶有索引的標簽欄。
這是我在應用程序委托中的源代碼:
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
}
你有什么建議嗎?
這個問題的答案取決於太多的事情,甚至無法將其放入評論中:
無論如何,最好的辦法是檢查您是否有當前的導航控制器,然后將新的導航控制器推入其中。 假設(1)是true,(2)是true,並且(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點起作用。 如果這不是一個選擇,那么仍然有可能嵌入視圖控制器 。 但是要這樣做,則(2)必須為false,甚至選項卡欄也不能位於導航控制器的層次結構中,該導航控制器具有可見的導航欄才能工作...
您發布的代碼在您的導航體系結構中看起來相當龐大,因此希望您能從中學到一些東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.