iOS Tutorial Multiple Pages Example

Erel

Administrator
Staff member
Licensed User
This example demonstrates how you can use a different code module for each page.

B4i structure (like B4J) is very flexible. Pages are regular objects like all other objects. You can use a single module for multiple pages or you can use multiple modules.

In this example we use a different module for each page.

Each module exposes a Show sub that initializes the page if needed and shows it:
B4X:
Public Sub Show
   If pg.IsInitialized = False Then
     pg.Initialize("pg")
     pg.RootPanel.LoadLayout("Page1Layout")
     pg.HideBackButton = True '<-- don't want to allow the user to return to the login screen
   End If
   Label1.Text = "Hello " & LoginModule.txtName.Text
   Main.NavControl.ShowPage(pg)
End Sub
 

Attachments

vikingivesterled

Member
Licensed User
In the ThreePages sample, the Main page don't actually show a page.
Would it cause a problem if it did? Sample if one had the login on the Main page.

Additionally if one go from a sub page to a previous page by kicking off another module on it instead of using Main.NavControl.RemoveCurrentPage
would one not cause the iPhone built in back selection to go back to the sub page?
(If one don't hide the back button)
 

vikingivesterled

Member
Licensed User
There seem to be something there.
All the run initialize errors I had with initializing described in:

http://www.b4x.com/android/forum/threads/initializing-button-affects-multiline-setting.49931/

went away when I moved the page Main showed to a new code module,
even though that wasn't the page with the errors,
and made all the pages named the same:

pg.Initialize("pg")

Though the

If pg.IsInitialized = False Then

created a problem with left overs on CustomListView's
that .Clear didn't fix.
Works fine if I initialize the page every time.
 

stari

Active Member
Licensed User
This example demonstrates how you can use a different code module for each page.

B4i structure (like B4J) is very flexible. Pages are regular objects like all other objects. You can use a single module for multiple pages or you can use multiple modules.

In this example we use a different module for each page.

Each module exposes a Show sub that initializes the page if needed and shows it:
B4X:
Public Sub Show
   If pg.IsInitialized = False Then
     pg.Initialize("pg")
     pg.RootPanel.LoadLayout("Page1Layout")
     pg.HideBackButton = True '<-- don't want to allow the user to return to the login screen
   End If
   Label1.Text = "Hello " & LoginModule.txtName.Text
   Main.NavControl.ShowPage(pg)
End Sub
Nice. But is possible to slide these panels (Sliding panels like in Android) ?
 

little3399

Active Member
Licensed User
Hi, Erel
How to implementation the Page1_Appear/Disappear function in this tutorial ? tks!
 

dieterp

Active Member
Licensed User
I set buttons in the Designer to be positioned in a random place for a page (Venues). I then call 'pg.RootPanel.LoadLayout("Venues")' to set the relevant layout to the page in the 'Public Sub Show' Sub. After calling that I reposition the buttons depending on whether or not there are records in the database linked to that screen.

However, as soon as I reach 'End Sub' (Of the 'Public Sub Show' Sub) the buttons are reset to where I set them in the Designer. How can I ensure that my changes to the button positions are not overwritten in this instance?
B4X:
Public Sub Show
   
    pg.Initialize("pg")
    pg.Title = "Venues"
    pg.RootPanel.LoadLayout("Venues") 'Load the Venues Layout

    Main.NavControl.ShowPage(pg)
   
    PopulateVenueList 'Here I re-position the buttons depending on whether I have records or not

End Sub 'At this point my changes get overwritten as per what is in the Designer
 

JonPM

Well-Known Member
Licensed User
I set buttons in the Designer to be positioned in a random place for a page (Venues). I then call 'pg.RootPanel.LoadLayout("Venues")' to set the relevant layout to the page in the 'Public Sub Show' Sub. After calling that I reposition the buttons depending on whether or not there are records in the database linked to that screen.

However, as soon as I reach 'End Sub' (Of the 'Public Sub Show' Sub) the buttons are reset to where I set them in the Designer. How can I ensure that my changes to the button positions are not overwritten in this instance?
B4X:
Public Sub Show
  
    pg.Initialize("pg")
    pg.Title = "Venues"
    pg.RootPanel.LoadLayout("Venues") 'Load the Venues Layout

    Main.NavControl.ShowPage(pg)
  
    PopulateVenueList 'Here I re-position the buttons depending on whether I have records or not

End Sub 'At this point my changes get overwritten as per what is in the Designer
You may want to try moving PopulateVenuesList to the pg_Resize(Width as int, Height as int) sub
 
Top