iOS Question NavigationController in TabBarController

Cadenzo

Active Member
Licensed User
Longtime User
I read the thread NavigationBar inside TabBarController, but it is still not clear for me. I want to handle the 4 main pages in a TabBarController, lets say page1, page2, page3 and page4. So page1 has a TableView and depending on the click-choice in this list, I want to show a new page "pgData". This can not be a part of the TabBarController, so after showing this pgData there should be a navigation back. The same with the page "pgSettings", shown from the Page2. So I also need a Navigationcontroller. Is that possible? I anderstood, that I can add the NavigationController somehow like a page in the TabBarController. But I was not successful with that. Can someone please explain this with my 6 exemplepages?
 

Cadenzo

Active Member
Licensed User
Longtime User
To answer myself on my question: For each page in an TabBarController, from where you want to navigate to subpages, you need to create an own NavigationController, add the (start) page to it and add this Controller to the TabBarController, instead of the page itself. You can public the NavigationControllers in the main module, if you want to handle the subpages in its own codemodule.
B4X:
Sub Process_Globals
    Public App As Application
    Private Page1, page2, page3, page4 As Page
    Private tbc As TabBarController
    Public nav1, nav2, nav3, nav4 As NavigationController
End Sub

Private Sub Application_Start (Nav As NavigationController)
    tbc.Initialize("tbc")
    App.KeyController = tbc
    Page1.Initialize("Page1")
    ' ...
    nav1.Initialize("nav1")
    nav2.Initialize("nav2") '...

    tbc.Pages = Array(nav1, nav2, nav3, nav4)
    
    nav1.ShowPage(page1)
    nav2.ShowPage(page2) '...
End Sub

It is not easy for Android-user to get into the concept of iOS. One more problem for me is, how to handle one subpage, if it should be called from more than one page in the TabBarController. Lets say, that the pgSettings can be called from page1 and also from page2.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Worth going over this simple example: Multiple Pages Example
The pages handling in iOS is much simpler than in Android.

how to handle one subpage, if it should be called from more than one page in the TabBarController
You can show the same page. Make sure to remove it from the previous navigation controller first.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Yes, I know this example and I use this show method. Thats why I made the Navigationcontroller public in my example.
So if I want to show a subpage1 from my page1, I can do it with nav1.ShowPage(subpage1). And if I want to show a subpage2 from the subpage1 I can do it with Main.nav1.ShowPage(subpage2). But it becomes complicated, if I also want to show the subpage2 from Page2. This would be over the nav2 in my example. So if I decide to use a TabBarController than I should know, that it is not so easy to show any sequences of subpages from any pages in the TabBarController, right?
 
Upvote 0
Top