Accessing properties across views

  1. last week

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

    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 :)

  2. Bob K

    Aug 12 Pre-Release Testers, Xojo Pro Kansas City

    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.

  3. Edited last week

    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.

  4. Bob K

    Aug 12 Pre-Release Testers, Xojo Pro Kansas City

    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

  5. Edited last week

    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 ?
  6. Bob K

    Aug 12 Pre-Release Testers, Xojo Pro Kansas City

    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.

  7. 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://docs.xojo.com/Class , https://docs.xojo.com/Inherits ).

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

  8. Emile S

    Aug 12 Europe (France, Strasbourg)

    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 ! ;)

  9. Gavin S

    Aug 12 Pre-Release Testers UK

    @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://docs.xojo.com/Class , https://docs.xojo.com/Inherits ).

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

    Check out Xojo's iOS Tutorial at https://docs.xojo.com/GettingStarted:iOS_Tutorial

    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.

  10. Edited last week

    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 :)

  11. 7 days ago

    Michel B

    Aug 12 Pre-Release Testers, Xojo Pro RubberViews.com

    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 :)

or Sign Up to reply!