iOS Question Completely remove the data from page once I leave it?

Discussion in 'iOS Questions' started by Shay, Jan 29, 2015.

  1. Shay

    Shay Well-Known Member Licensed User

    I have strange problem
    I am using this code on each code module page:

    Code:
    Public Sub Show
        
    If PG.IsInitialized = False Then
            PG.Initialize(
    "pg")
            PG.RootPanel.LoadLayout(
    "PageX")
            PG.Title = Main.AppTitle
            PG.RootPanel.Color = 
    Colors.RGB (54,54,54)
            PG.HideBackButton = 
    True ' block button back
        End If
        Main.NavControl.ShowPage(PG)
    the problem is when I leave the page and come back to it
    all the data is still there (can be also CustomListVew with data)

    When I am leaving the page I tried even :
    Code:
    PG.RootPanel.RemoveAllViews   
        PG.RootPanel.RemoveViewFromParent
        scvMain.RemoveViewFromParent
        PG.RootPanel.RemoveAllViews
        Main.NavControl.RemoveCurrentPage
    but once I enter the page again all my vars (such as PG, scvMain, etc..) are still initialized
    (also tried to init them again, did not help)

    How do I completely remove the data from page once I leave it?
     
  2. susu

    susu Well-Known Member Licensed User

    Try to move all that "remove" into

    Private Sub pg_Disappear
    ...
    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can put the page in a class instance and then create a new instance any time you want a new page.
     
  4. Shay

    Shay Well-Known Member Licensed User

    I need your help writing this class,
    (never wrote class)
    I wrote this, but the issue is that it is not recognizing the layout objects, so it crash on first object (such as label)
    (also editor is marking all the vars as not initialized)

    Code:
    'Class module
    Sub Class_Globals
        
    Public PG As Page
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(Layout As String)

        
    If PG.IsInitialized = False Then
         PG.Initialize(
    "pg")
         PG.RootPanel.LoadLayout(Layout)
         PG.Title = 
    "MyApp"
         PG.HideBackButton = 
    True ' block button back
        End If
        Main.NavControl.ShowPage(PG)
      
    End Sub
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You should move all the code from the module to the class. The views variables should be declared in the class.
     
  6. Shay

    Shay Well-Known Member Licensed User

    but I have many modules and for each module it has it own layout, so can't I do something generic in the class, or I need class for each page/module?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You just need to use classes instead of modules. This way you will be able to create new instances of your pages.

    (assuming that you really want to clear the state of each page).
     
  8. Shay

    Shay Well-Known Member Licensed User

    Tried:
    I moved all the code from the module to class (Class name NewPage)
    from module1 I am writing:
    Dim Step3 As NewPage
    Step3.Show

    on Class it is crashing on:
    If PG1.IsInitialized = False Then


     
  9. Shay

    Shay Well-Known Member Licensed User

    ok, I figure it
    I changed the subname from "show" to:
    Public Sub Initialize
     
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