Static reference to instance method

I have four Views (e.g. wordsView and timerView) in my iOS app linked by one tab bar. When I try to access the values of one View from another e.g. enabling the Pause button on timerView from within a method on wordsView I have the line:

I get this error:

I have checked the manual and searched the forums for the error, but cannot see how to access the controls in one View from a different View. Any hints?

The error looks as if you created a class timerView and try to access it like an instance. Check if the real view’s name is different, maybe timerView1?

1 Like

[quote=157566:@David Cox]I have four Views (e.g. wordsView and timerView) in my iOS app linked by one tab bar. When I try to access the values of one View from another e.g. enabling the Pause button on timerView from within a method on wordsView I have the line:

timerView.pauseButton.Enabled = True
I get this error:

Static reference to instance method: call this on an instance of class timerView.timerView
I have checked the manual and searched the forums for the error, but cannot see how to access the controls in one View from a different View. Any hints?[/quote]

You should create an instance and then you can access controls and properties into it.

Create v as new timerView timerView.pauseButton.Enabled = True

But then, if you want the said view to reflect the change, that is the one you need to PushTo. If you use tabs, you should make v a module view property and pushto that in timerView activate.

@Ulrich Bogun the View names are correct and show up when using the tab to fill in the values.

@Michel Bujardet I understand the idea of having one View create another View dynamically as you drill down e.g. EddiesElectronics using the PushTo command, but I am not drilling down.

I have four static Views that are visible from launch time. I have a tab bar on the bottom row set up from the ‘iPhoneScreen’ iosScreen object. I can jump from one View to another using the tab bar. One of my Views holds some Options values that I want to refer to in another View, but gives an error when referencing the fields in a different View.

My problem is that if I use the Dim v as new timerView I will be accessing a new instance of the View, not the one that is currently visible.

I don’t understand the error, so I don’t know how to resolve it!

You could add a couple of variables to the app class as iOSview. On the open event of each tab, set the corresponding variable = self.

Then from the tabs, you can reference those app variables to access the other tabs.

timerView(app.timerViewTab).pauseButton.Enabled = True

This is how I implemented @Scott Siegrist 's method:

  1. I created four new variables in the App section — one per View — and prefixed ‘app’ on their View name e.g. appWordsView and set their type as the View e.g. wordsView (i.e. not as type iosView).
  2. In the Open event of each View I set the App property e.g. app.appWordsView = self
  3. Now I can refer to objects on one View from another View e.g. from optionsView I can now code:

[quote] if app.appWordsView.tickingSoundSwitch.Value then
ClockTick.Play
end if
[/quote]

I still don’t know why I cannot access the screen items directly, but this is a suitable workaround. Thank you to all contributors.