iOS Tutorial Multiple Pages Example

Discussion in 'iOS Tutorials' started by Erel, Dec 14, 2014.

  1. Erel

    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:
    Code:
    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
     

    Attached Files:

  2. klaus

    klaus Expert Licensed User

    You find another example, iSQLiteLight3 in my signature.
     
    Erel likes this.
  3. vikingivesterled

    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)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No. It doesn't matter. You can use any module to show any number of pages.

    If the page is already in the stack then all the pages above it will be removed.
     
    Intiwhiz likes this.
  5. vikingivesterled

    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.
     
  6. stari

    stari Active Member Licensed User

    Nice. But is possible to slide these panels (Sliding panels like in Android) ?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    This is a hierarchical structure. It is not the same as the sliding panels example in Android. You can slide to the previous page (this is a standard OS feature).
     
  8. Mashiane

    Mashiane Expert Licensed User

    Perfect!
     
  9. little3399

    little3399 Active Member Licensed User

    Hi, Erel
    How to implementation the Page1_Appear/Disappear function in this tutorial ? tks!
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Nothing special You just need to add the event. For example:
    Code:
    Sub pg_Appear
       
    End Sub
     
    valentino s likes this.
  11. little3399

    little3399 Active Member Licensed User

    Tks , Erel
     
  12. dieterp

    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?
    Code:
    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
     
  13. JonPM

    JonPM Well-Known Member Licensed User

    You may want to try moving PopulateVenuesList to the pg_Resize(Width as int, Height as int) sub
     
  14. dieterp

    dieterp Active Member Licensed User

    Hi @JonPM. That has done the trick. Thanks very much! :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice