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

Shay

Well-Known Member
Licensed User
I have strange problem
I am using this code on each code module page:

B4X:
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 :
B4X:
    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?
 

susu

Well-Known Member
Licensed User
Try to move all that "remove" into

Private Sub pg_Disappear
...
End Sub
 

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)

B4X:
'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
 

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?
 

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


Class (b4i_httpjob) instance released.
Error occurred on line: 21 (newpage)
Target is null. Method called: IsInitialized
Stack Trace: (
CoreFoundation <redacted> + 154
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Get Client +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 196
Get Client -[B4IShell runMethod:] + 496
Get Client -[B4IShell raiseEventImpl:method:args::] + 1846
Get Client -[B4IShellBI raiseEvent:event:params:] + 1316
Get Client __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 254
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1300
CoreFoundation CFRunLoopRunSpecific + 522
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 138
UIKit UIApplicationMain + 1136
Get Client main + 116
libdyld.dylib <redacted> + 2
)
 

Shay

Well-Known Member
Licensed User
ok, I figure it
I changed the subname from "show" to:
Public Sub Initialize
 
Top