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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to