iOS Question I don't fully understand the Page vs Code Module concept

jaraiza

Active Member
Licensed User
Longtime User
Hi,

Since I'm very used to B4A, I tried to do the same thing with B4i: Adding Code Modules and jump between them like I do with Activites, without luck.

Then I saw an example from Erel that uses Page1 and Page2 in the same code module.

IRL an app which depends on different menus / behaviours must be done in one or multiple code modules? In case of modules, how can I jump between them?

NavControl.ShowPage(AppMenu_02) seems to work, but then "CodeMod_02" breaks:

B4X:
NavControl.ShowPage(AppMenu_02)

ERROR:
Error occurred on line: 38 (main)
-[b4i_promo02 useLayoutToLayoutNavigationTransitions]: unrecognized selector sent to instance 0x14688440


Thanks for any help!
 

Eric Baker

Member
Licensed User
Longtime User
This seems to work for me. I create a new module with the following:

B4X:
'Code module

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.

   Private Button1 As Button
   Private Page2 As Page
End Sub

Public Sub ShowPage
   If Not(Page2.IsInitialized) Then
     Page2.Initialize("Page2")
     Page2.RootPanel.LoadLayout("S2")
   End If
   Main.NavControl.ShowPage(Page2)
End Sub

Sub Button1_Click
   Log("Click")
End Sub

Then I can show the module with: modulename.ShowPage

Works with designer, and all events can be in the module.
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
I checked your sample... But modulename.showPage only calls a sub in "modulename" , it's not like StartActivity/ActivityFinish. This just load the sub and then returns to its caller, it's something different.

Does iOS work that way?

Thanks!
 
Upvote 0

Eric Baker

Member
Licensed User
Longtime User
I am no expert, but as far as I know, IOS does not have activities like Android has. IOS has controllers (e.g. NavigationController is the default) that manage pages.

The page does have an Appear and Disappear event that you could use.

The NavigationController puts pages in a stack, and provides navigation (pop) back to the previous page. If you ShowPage a page already in the stack, all the pages added after that page will removed from the stack (e.g. if you return to your main page via ShowPage(Page1), all pages are removed from the stack and Page1 is shown again)

There is also a TabBarController available that you could use instead of a NavigationController. This controller allows you to switch pages by clicking on items in the tab bar.

As far as I know, these are the only controllers available now in B4I, maybe other IOS controller types will be added later.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can either use the same module or multiple modules or multiple classes. It is up to you.

Pages are not special objects.

You don't need to start a code module. It is not the same as B4A activity or service.

You can create a Show sub in your module if you like:
B4X:
Public Sub Show
 Main.NavControl.ShowPage(MyPage)
End Sub
 
Upvote 0

Eric Baker

Member
Licensed User
Longtime User
Erel,

I believe the context of Jaraiza's question was to create an app with a similar structure as a B4A app. Sure, you can create an app with only a "Main" module and create pages as needed, but for many multipage apps that gets messy really quickly, IMHO. I have read the Beginners Guide, the documentation and many posts in the forum, and did not find suggestions on how to structure a multipage app. I am sure there are many ways and it would be great to see other design patterns as well.

Thank you for B4I, it's an amazing tool. I can't wait to see how much better it gets over time thanks to you and hopefully many contributors for libs and mods.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The standard code module is equivalent to B4A Activity and Service modules. The only difference is that you don't need to worry about the code module life cycle.

Instead of calling StartActivity you should call Module1.Show (where show is the sub I posted above).

The code structure in B4i (which is the same as in B4J) is actually simpler than in B4A.
 
Upvote 0
Top