iOS Question BarButton_Click no longer fire

Discussion in 'iOS Questions' started by marcick, Jun 13, 2018.

  1. marcick

    marcick Well-Known Member Licensed 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:

    Code:
    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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Your code looks wrong. You shouldn't initialize a new page and load the layout each time that show is called.

    Good pattern: Multiple Pages Example

    Why aren't you adding the buttons with the designer?
     
  3. marcick

    marcick Well-Known Member Licensed 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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload the project? Or better a small project with only the relevant button?
     
  5. marcick

    marcick Well-Known Member Licensed User

    Yes, I'll take your sample and try to reproduce the problem
     
  6. marcick

    marcick Well-Known Member Licensed 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
     

    Attached Files:

    • 1.zip
      File size:
      7.5 KB
      Views:
      13
  7. Erel

    Erel Administrator Staff Member Licensed User

    You need to add the buttons in the layout that is loaded by the page. Main2 in this case.
     
  8. marcick

    marcick Well-Known Member Licensed User

    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 ?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You have uploaded a project and asked why the buttons do not work. I've answered that. If you have any other question then start a new thread with all the relevant information.
     
  10. marcick

    marcick Well-Known Member Licensed 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:

    Code:
    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 :)
     
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