• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Access object from another view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Access object from another view


  • Subject: Re: Access object from another view
  • From: Steve Wetzel <email@hidden>
  • Date: Tue, 21 Sep 2010 16:03:16 -0500

Thanks Everyone.

I could not get the

[self.viewController1.label2.text

or the

[self view addSubview:viewController2.view];

to work for some reason.  Then it dawned on me that I could set the value right before I added the Subview!

[viewController2.label2 setText:label1.text];
[self.view addSubview:viewController2.view];

This works, although for some reason the label does not update unless I reload the view.  I will figure out what is going on there.

Thanks for the suggestions.

Steve






On Sep 21, 2010, at Sep 21:3:25 PM, Conrad Shultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 9/21/10 11:57 AM, Steve Wetzel wrote:
>> How do I access and object on one view from another view?  I cannot
>> figure it out.
>>
>> I have two view controllers and two views.  Lets call them
>> viewController1 and viewController2 and view1 and view2.
>> ViewController1 loads the second view by:
>>
>> [self.view addSubview:viewController2.view];
>>
>> There is a label in view1 that I want to get the value of the text
>> from in the code for viewController2.  How do I do this?
>
> Caveat: you ought to listen to Quincey's advice, since it will give a
> more robust, or at least a cleaner, implementation.
>
> That said, for the specific situation at hand, UIView has a superview
> property that returns a reference to, well, the view's superview (if it
> exists).  If you have the label as a property of view1 ("theLabel"), you
> could do something like the following (in viewController2):
>
> UILabel *theLabel = [[[self view] superview] theLabel];
>
> If it's a tagged view, you could do something like:
>
> NSInteger labelTag = (whatever you set, probably in IB);
> UILabel *theLabel = [[[self view] superview] viewWithTag:labelTag];
>
> (Since properties are involved, you are of course free to use dot syntax
> in many places above if that's your preference.)
>
> - --
> Conrad Shultz
>
> Synthetiq Solutions
> www.synthetiqsolutions.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iD8DBQFMmRSvaOlrz5+0JdURApMYAJ0aAv996lOHMDyY5oTKg0ju0LIbIACePwij
> i3EBvDqS2WGzo+wnrBT9Mz8=
> =Ea2B
> -----END PGP SIGNATURE-----

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Access object from another view
      • From: Quincey Morris <email@hidden>
References: 
 >Access object from another view (From: Steve Wetzel <email@hidden>)
 >Re: Access object from another view (From: Conrad Shultz <email@hidden>)

  • Prev by Date: Re: Access object from another view
  • Next by Date: Re: Toolbar Item -Menu Form Representation - Key Equivalent
  • Previous by thread: Re: Access object from another view
  • Next by thread: Re: Access object from another view
  • Index(es):
    • Date
    • Thread