iOS Question Reference a Page via a variable

CryoGenID

Active Member
Licensed User
Longtime 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:
B4X:
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
 

narek adonts

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0

CryoGenID

Active Member
Licensed User
Longtime 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
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
I think that you are calling your Sub before showing a page. So the most easy way was
B4X:
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

B4X:
    Dim pg As Page
    Dim no As NativeObject=navcontrol
    pg=no.GetField("topViewController")

Hope it helps

Narek
 
Upvote 0

MotoMusher

Active Member
Licensed User
Longtime 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.
 
Upvote 0
Top