Re: Access object from another view
Re: Access object from another view
- Subject: Re: Access object from another view
- From: Conrad Shultz <email@hidden>
- Date: Tue, 21 Sep 2010 13:25:19 -0700
-----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