iOS Question BarButton_Click no longer fire

marcick

Well-Known Member
Licensed User
Longtime User
Following this thread https://www.b4x.com/android/forum/threads/iphone-x-safe-area.88095/#content
I have modified my code to suit well the Iphone X screen not using the dangerous area.
It works ok, but the problem is when I switch to a secondary page: I can see the top left toolbar text (back button), but I'm no longer able to modify the text in runtime and have events when I click it.

This is the code of a secondary page:

B4X:
Public Sub Show
    pg.Initialize("Page1")
    pg.RootPanel.LoadLayout("Root")
    Dim buttons As List                                >>> these lines of code to change
    buttons.Initialize                                    >>> the back button text no longer works
    Dim newButton As BarButton
    newButton.InitializeText("Salva","Salva")
    buttons.Add(newButton)
    pg.TopLeftButtons=buttons
    PnlRoot.LoadLayout("WebSync")
    pg.Title="WebSync"
    pg.RootPanel.Color = Colors.white   
    Main.NavControl.ShowPage(pg)
    Main.NavControl.NavigationBarVisible = True
    Main.NavControl.ToolBarVisible=False
End Sub


Sub Page1_BarButtonClick (Tag As String)        >>> and this event is no longer fired
     Select Tag
        Case "Salva"

Other events of Page1, for example "Page1_KeyboardStateChanged" works, but not "Page1_BarButtonClick"

Where I'm wrong ?
 

marcick

Well-Known Member
Licensed User
Longtime User
I just need the back button, but need to change the text.
I'll have a look again to the link above, but the main problem is that I don't have the Page1_BarButtonClick event fired.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I'm sure I'm doing some stupid errors, but here is the sample where I can't get fired the page1 and pag2 events
 

Attachments

  • 1.zip
    7.5 KB · Views: 247
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
You need to add the buttons in the layout that is loaded by the page. Main2 in this case.

1) Why the "Page1_KeyboardStateChanged" in the mainpage is not fired ?
2) I need just the back button in the top left corner, and I see it. Do I have to add it in the layout (and how) to have the events ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Sorry. I appreciate your efforts and patience to reply at every (also stupid) question while you work to the B4x platform too ...
I see that button events are correctly triggered for buttons declared in the designer.
But the back button can't be defined in the designer and to have the event also on it you must hide it and replace with code in runtime.
Like this:

B4X:
Public Sub Show
    If page2.IsInitialized = False Then
        page2.Initialize("page2")   
        page2.RootPanel.LoadLayout("2")
    End If
    Main.NavControl.ShowPage(page2)
    ReplaceBackButton(page2, "< titolo", "Tag")
End Sub

Sub page2_BarButtonClick (Tag As String) 
    Log(Tag)
End Sub

Sub ReplaceBackButton(pg As Page, Title As String, Tag As String)
    pg.HideBackButton=True
    Dim buttons As List
    buttons.Initialize
    Dim newButton As BarButton
    newButton.InitializeText(Title, Tag)
    buttons.Add(newButton)
    pg.TopLeftButtons=buttons
End Sub

Now, still have issue with the keyboard event so I'll start a new thread. Thanks :)
 
Upvote 0
Top