iOS Question [SOLVED] return to main page from a new page create (Newbie)

akinnovation

Member
Licensed User
Longtime User
Hi all,
I'm newbie for b4i and for b4xpages. In my first app per IOS I had a button in my mainpage that open a new page I need to close this page and return to main page.
I try to use closepage(me), but the page isn't close and in the log appear a message "First page cannot be closed". How I can return to mainpage ?

Many thanks to all community, it's the pillar (with Erel) of B4X
 

William Lancee

Well-Known Member
Licensed User
Longtime User
If you zip the project with 'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Which is line 6 of B4XMainPage. Then you can attach it as a file and we can look at it to see where you went wrong.

I have not see that issue before so there is something wrong with your code.
 
Upvote 0

akinnovation

Member
Licensed User
Longtime User
This is the project I nave started from world population demoapp.
I have also another trouble when I press the "Lista" button in the main page if I don't put a breakpoint on the b4xpage_created, the app crash. If I I put the breakpoint and than I press go all work fine.
Many thanks

P.S. I can't succeded in atacch the file(too big file) so I put the most important lines of code.

open the new page:
Private Sub Lista_Click
    oratim.Enabled=False
    
    B4XPages.ShowPageAndRemovePreviousPages("Scelta") 'era ShowPageAndRemovePreviousPages con showpage mostra anche la possibilità di tornare indietro
    oratim.Enabled=True
End Sub

creation of the new page:
Private Sub B4XPage_MenuClick (Tag As String)
    Log(Tag)
    If Tag="indietro" Then 'BACK
        livelloscelto=livelloscelto-1
        If livelloscelto>=0 Then
            scegliquery(livelloscelto,"",sottogrupposcelto)
        Else
            B4XPages.ClosePage(Me) 'try to close page
        End If
        
    End If
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("SearchResults")
    'load the layout to Root

    B4XPages.SetTitle(Me, "SCEGLI") 'Page title

    B4XFltTxtSearch.HintText = "Search"
    B4XFltTxtSearch.Update   

    CLVSearchResults.sv.Color = XUI.Color_White
    'Query the SQLite database to populate the results
    
    'SQLQuery("select distinct u.id,coalesce(u.citta,"&"""GENERALI"""&") As descr from anaute u order by u.citta","CITTA")
    scegliquery(0,"","")
End Sub

Sub scegliquery(livello As Int ,tipo As String, param As Object)
    Dim sql As String
    livelloscelto=livello
    If livello=0 And Main.parametri.sottogruppo>=0 Then
        sql="select id,descrizione as descr from anaditte_sottogruppi where idditta="&Main.parametri.idditta&" and stato='A' order by descrizione"
        sottogrupposcelto=-1
    End If
    If livello=1 Then
        sottogrupposcelto=param.As(Int)
        If Main.parametri.comuni Then
            sql="select distinct coalesce(u.citta,"&"""GENERALI"""&") As descr from anaute u "
                If Main.parametri.sottogruppo=0 Then
                    sql=sql&"where coalesce(idsottogruppo,0)="&sottogrupposcelto&"  order by descr"
                Else
                    sql=sql& " order by descr"
                End If
        End If
    End If
        
    If livello=2 Then
        sql="select distinct u.id,upper(coalesce(u.nome,"&""""""&")||"""&" "&"""||coalesce(u.cognome,"&""""""&")) As descr, u.tipo_marcatura from anaute u where coalesce(upper(citta),"&""""""&")="""& param.as(String).ToUpperCase &""" "
        If Main.parametri.sottogruppo>=0 Then
            sql=sql&"and coalesce(idsottogruppo,-1)="&sottogrupposcelto&" order by descr"
        Else
            sql=sql& "order by descr"
            End If
    End If

SQLQuery(sql,tipo,livello)   
End Sub

' fill the CLV
Sub SQLQuery(Query As String,tipo As String,livello As Int)
    Dim item As String
    
'    Dim parametri As List
'    If parametro<>"" Then
'        parametri.Initialize
'        parametri.InsertAt(0,parametro)
'    End If
    CLVSearchResults.Clear 'Clear the CustomListView
    
    Dim SenderFilter As Object = B4XPages.MainPage.SQL.ExecQueryAsync("SQL", Query, Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    If Success Then
        Do While rs.NextRow 'Loop through the results
            'Ceate your custom type (on a per line basis)
            'PCLV.AddItem(260dip, XUI.Color_White, CreateRowSearchResultData(rs.GetString("Country"), rs.GetInt("Year"), rs.GetString("Male"), rs.GetString("Female"), rs.GetString("Total")))
            'item=rs.GetString("descrizione")
            'CLVSearchResults.add
            Dim ResultValues As RowSearchResultData
            ResultValues.Initialize
            ResultValues.descr=rs.GetString("descr")
            ResultValues.id=rs.GetInt("id")
            ResultValues.livello=livello
            CLVSearchResults.AddTextItem(ResultValues.descr,ResultValues)
        Loop
        rs.Close
    Else
        Log(LastException)
    End If
End Sub

log of creation and closing:
Copying updated assets files (1)
Application_Start
*** mainpage: B4XPage_Created
Application_Active
Database copied = 1
Database size = 28672
*** mainpage: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** scelta: B4XPage_Created [mainpage]
*** mainpage: B4XPage_Disappear [scelta]
*** scelta: B4XPage_Appear [scelta]
*** scelta: B4XPage_Resize [scelta]
*** scelta: B4XPage_MenuClick [scelta]
indietro
First page cannot be closed
Application_Inactive
Application_Active
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The B4XPages.ShowPageAndRemovePreviousPages("Scelta") removes B4XMainPage
So you have nothing to go back to. In B4J and B4A the app is exited. I don't know about B4i.
In any case I think you want B4XPages.ShowPage("Scelta")
 
Upvote 0
Top