iOS Question [B4XPage] How to prevent page closing

Alexander Stolte

Expert
Licensed User
Longtime User
If the user closes the page but there are still unsaved changes, I would like to show the user a warning and give them the option to cancel the action.
How does this work with B4XPages?

Thanks
 

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
I've been able to simulate the page close event on B4i with the following trick.
You can check if this allows the LucaMS suggestion to work for you

B4X:
Sub B4XPages_Disappear
    #if B4i
    Dim PageClosed As Boolean = Not(B4XPages.GetManager.mStackOfPageIds.Contains(B4XPages.GetPageId(Me)))
    If PageClosed Then
        B4XPage_CloseRequest
    End If
    #end if
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
When that event is triggered on that page (even several times) it will always be in the stack, otherwise how could it be triggered?

1711648567646.png


:oops:
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
the Disappear event is triggered _after_ the page has been closed, so it's not on the stack anymore.
maybe not exactly what Alexander was searching, but it could be starting point
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can prevent the user from closing the page, but if this option is enabled then you aren't expected to cancel it. The user can close the page with a swipe.

B4X:
B4XPages.GetNativeParent(Me).HideBackButton = True
Another option is to show the page with B4XPages.ShowPageAndRemovePreviousPages.

You can then add a "close" button and handle its event.
 
Upvote 0
Top