Accessing properties across views

If View1 is called by View2, how can View2 access a property of View1?

Several ways to accomplish this.

You can pass the property from View1 to View2.

You could pass a reference of View1 to View2 and have View2 access the property directly.

You make that property global so both View1 and View2 can use it without having to pass anything.

Thanks Bob!
Would you be able to help with some sample code please.
Although I understand the programming concepts, I just started working with Xojo and iOS dev in general, so some sample code will help a lot.

I’m calling View2 from View1 as follows,

Dim v As New View2
Self.PushTo(v)

I would like to access the property MyInfo defined in View1 from View2.

Passing the property from view1 to view2
Dim vw As New view2(SomeProperty) //Constructor for View2 must accommodate this
Self.pushto(vw)

Passing View1 into View2 so view2 can access view1 properties
Dim vw As New view2(Self) //Constructor for View2 must accommodate this
Self.pushto(vw)

In both cases you’ll have the create a Constructor with the proper parameters to pass in.

Global property. Create a module. Add property and set scope to Global.
So in View1and View2 you’d access it like this:
module1.SomeProperty

This is perfect!
Although I would need help to get started on creating classes now.

  1. Should I inherit from iOS View and create a class and define the constructor? Some sample code would be great.
  2. Where should the code be defined so that I can use the new class in my application ?

I think you should spend some time reading through documentation and looking at example projects that come with Xojo and playing around with your own smaller sample projects. The forum can help but you’ve got to put in some work on your own.

True I understand :).

I did do some searches to try to find some more information before typing in my question on classes on the documentation and forum posts. The following pages I found were not very helpful ( https://documentation.xojo.com/api/language/class.html, https://documentation.xojo.com/api/language/inherits.html).

Are there any pages on the documentation that you could recommend for further reading?
This will be my last question :wink: Thanks in advance.

Oh ! You meant iOSView !

a. There is an iOS channel,
b. it will be better for you to specify the platform in the subject too.
c. Welcome ! :wink:

[quote=450255:@Upuli G]True I understand :).

I did do some searches to try to find some more information before typing in my question on classes on the documentation and forum posts. The following pages I found were not very helpful ( https://documentation.xojo.com/api/language/class.html, https://documentation.xojo.com/api/language/inherits.html).

Are there any pages on the documentation that you could recommend for further reading?
This will be my last question :wink: Thanks in advance.[/quote]

Check out Xojo’s iOS Tutorial at https://documentation.xojo.com/getting_started/tutorials/ios_tutorial.html

There’s also a Xojo YouTube channel at https://www.youtube.com/user/goxojo/featured and if you dig into that, you should find an iOS playlist.

Finally, as Bob said, open the Examples folder that comes with Xojo and tear apart all the iOS examples. That’s probably the quickest way to get started. After that, you can drill down into the docs as required.

I ended up with a simple solution. Creating a property in View2, and assigning it the value from View1

Dim v As New View2
Self.PushTo(v)

v.MyInfo2 = MyInfo // MyInfo is the property in View1 which I need in View2

Thanks everyone for your helpful comments :slight_smile:

You may want to change the channel to iOS, so when other members look for the same topic, they will find it more easily.

And next time you post about an iOS specific question, better post in the iOS channel :slight_smile: