# Accessing properties across views

**URL:** <https://forum.xojo.com/t/accessing-properties-across-views/49842>\
**Category:** iOS\
**Created:** [August 12, 2019, 2:38pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842 "2019-08-12T14:38:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Upuli\_G](https://forum.xojo.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@Upuli\_G](https://forum.xojo.com/u/Upuli_G)\
**Post date:** [August 12, 2019, 2:38pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/1 "2019-08-12T14:38:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bob\_Keeney](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bob\_Keeney](https://forum.xojo.com/u/Bob_Keeney)\
**Post date:** [August 12, 2019, 2:46pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/2 "2019-08-12T14:46:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Upuli\_G](https://forum.xojo.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@Upuli\_G](https://forum.xojo.com/u/Upuli_G)\
**Post date:** [August 12, 2019, 2:55pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/3 "2019-08-12T14:55:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bob\_Keeney](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bob\_Keeney](https://forum.xojo.com/u/Bob_Keeney)\
**Post date:** [August 12, 2019, 3:01pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/4 "2019-08-12T15:01:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Upuli\_G](https://forum.xojo.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@Upuli\_G](https://forum.xojo.com/u/Upuli_G)\
**Post date:** [August 12, 2019, 3:30pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/5 "2019-08-12T15:30:08Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Bob\_Keeney](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bob\_Keeney](https://forum.xojo.com/u/Bob_Keeney)\
**Post date:** [August 12, 2019, 3:35pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/6 "2019-08-12T15:35:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Upuli\_G](https://forum.xojo.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@Upuli\_G](https://forum.xojo.com/u/Upuli_G)\
**Post date:** [August 12, 2019, 3:58pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/7 "2019-08-12T15:58:07Z")

</div>

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/class.html), [https://documentation.xojo.com/api/language/inherits.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 😉 Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [August 12, 2019, 4:27pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/8 "2019-08-12T16:27:37Z")

</div>

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 ! 😉

---

<div class="post-metadata">

**Author:** ![Gavin\_Smith](https://forum.xojo.com/user_avatar/forum.xojo.com/gavin_smith/32/13901_2.png) [@Gavin\_Smith](https://forum.xojo.com/u/Gavin_Smith)\
**Post date:** [August 12, 2019, 4:42pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/9 "2019-08-12T16:42:04Z")

</div>

[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/class.html), [https://documentation.xojo.com/api/language/inherits.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 😉 Thanks in advance.[/quote]

Check out Xojo’s iOS Tutorial at [https://documentation.xojo.com/getting\_started/tutorials/ios\_tutorial.html](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](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.

---

<div class="post-metadata">

**Author:** ![Upuli\_G](https://forum.xojo.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@Upuli\_G](https://forum.xojo.com/u/Upuli_G)\
**Post date:** [August 12, 2019, 4:44pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/10 "2019-08-12T16:44:47Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 12, 2019, 8:36pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/11 "2019-08-12T20:36:25Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:03pm UTC](https://forum.xojo.com/t/accessing-properties-across-views/49842/12 "2021-04-29T16:03:26Z")

</div>


