iOS Question Reference a Page via a variable

Discussion in 'iOS Questions' started by CryoGenID, Mar 6, 2015.

  1. CryoGenID

    CryoGenID Active Member Licensed User

    Hello everybody,

    I currently have a problem and would be happy if anybody could help me out :)

    I would like to write a generic function which finds out which page is currently active and then enables/disables buttons of the ToolBar (BarButtons) accordingly.

    My problem now is:
    1) How do I find out which page us currently active?
    2) How would I access that Page dynamically? See <CURRENT_PAGE> in the example below...

    NON WORKING example:
    Code:
    Sub Generic_BarButtonDisableByTag (Tag As String)
       
    Dim buttons As List = <CURRENT_PAGE>.ToolbarButtons
       
    For i = 0 To buttons.Size - 1
         
    Dim bb As BarButton = buttons.Get(i)
         
    If bb.Tag = Tag Then
             bb.Enabled = 
    False
           
    Exit
         
    End If
       
    Next
       pageIn.ToolbarButtons = buttons
    End Sub
    Even if I somehow (see question 1) knew the name of the page, the other problem (see question 2) unfortunately still remains :(

    I would be very happy if you could help me out :)

    Thanks a lot and best regards,

    Christian
     
  2. narek adonts

    narek adonts Well-Known Member Licensed User

    Why you are not changing the BarButtons before showing the page.

    For example to show Page with its BarButtons.

    1. Create BarButtons for Page1
    2. Show Page1

    And change the BarButtons each time before showing a page.

    Narek
     
  3. CryoGenID

    CryoGenID Active Member Licensed User

    Hello Narek,

    thanks for your reply :)

    That is exactly what I am planning to do... The only "problem" is that I try to use generic functions wherever possible,
    so I have created the function (see my first post) where I would like to give the name of the Page I want to display and have the generic function
    do that for me... Then I only have one place to do changes ;-)

    But for that to work I need to solve problem #2 of my problems list in my first post ;-)

    Best regards,

    Christian
     
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    I think that you are calling your Sub before showing a page. So the most easy way was
    Code:
    Sub Generic_BarButtonDisableByTag (Tag As String, CurrentPage as Page)
       
    Dim buttons As List = CurrentPage.ToolbarButtons
       
    For i = 0 To buttons.Size - 1
         
    Dim bb As BarButton = buttons.Get(i)
         
    If bb.Tag = Tag Then
             bb.Enabled = 
    False
           
    Exit
         
    End If
       
    Next
       pageIn.ToolbarButtons = buttons
    End Sub

    And after

    Generic_BarButtonDisableByTag(Tag, Page1)
    Navcontrol.show(Page1)

    But if you need anyway to know the current page try this

    Code:
    Dim pg As Page
        
    Dim no As NativeObject=navcontrol
        pg=no.GetField(
    "topViewController")
    Hope it helps

    Narek
     
    yiankos1 likes this.
  5. MotoMusher

    MotoMusher Active Member Licensed User

    If you want to stay generic, you could do it like this.

    In Main, create a public variable

    Public CurrentPage as String

    On subsequent pages, update Main.CurrentPage in somepage_resize, or another sub which will always fire when page is active

    Main.CurrentPage = "MyOtherPage"

    Create a class for your tabs, and just reference main.currentpage in there. Main should always be initialized and available. You could put the variable it in the class as well.
     
  6. CryoGenID

    CryoGenID Active Member Licensed User

    Thanks to you both :)

    I will try to use your examples and best practices :)

    Best regards,

    Christian
     
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