0

We are designing an ios application and we have a problem with tabbar.

We have some pages that are not shown in tabbar. User can only access these pages when they click buttons in pages. Thus, we didn't connect them to tabbar.

If user open the app and click buttons, tabbar shown in these pages properly. This is what I want, tabbar should be shown in each page.

However if a user click a shared link such as "myApp://pageToShow" and I directly push user to this page from app delegate, tabbar is not shown. Since page is not belong to tabbar, I cannot present tabbar with index.

Here is my source code in 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
}

Do you have any suggestion?

1 Answers1

0

The answer to this question depends on too many things to even put it inside a comment:

  1. Is this code inside a view controller which is inside a tab bar?
  2. Do controllers inside tab bar have their own navigation controllers?
  3. What does the code that hides this view controller look like?

Anyway, the best would be to check if you have a current navigation controller and push the new one to it. This assumes (1) is true, (2) is true and (3) is ready to handle navigation back from it:

    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
    }

If this is not the case then I guess make the 3 points work. And if that is not an option there is still a possibility of embedding a view controller. But to do so then (2) must be false and even the tab bar must not be in hierarchy of a navigation controller which has a visible navigation bar to work...

The code you posted looks like quite a mass in your navigation architecture so I hope you learn something from it.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • Thank you for your answer. The view named as RestStory is inside of RestStoryNavbar. However, they are not inside of tabbar. Although they are not inside a tabbar, I want to show tabbar in this page because otherwise user won't be able to go other views in application. So, 1) False, 2)True, 3) There is no code hides it, but I guess I need to add some code to show this. I tried many things but none of them worked. –  Nov 29 '17 at 13:56
  • It is quite likely to have navigation controller within which there is a tab bar controller where each of its view controllers is a navigation controller.... – Matic Oblak Nov 29 '17 at 14:46