Re: Access object from another view
Re: Access object from another view
- Subject: Re: Access object from another view
- From: Quincey Morris <email@hidden>
- Date: Tue, 21 Sep 2010 16:03:05 -0700
On Sep 21, 2010, at 14:03, Steve Wetzel wrote:
> 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.
The usual cause of such behavior is the timing of NIB loading. There are various points at which code can be executed (init..., awakeFromNib, viewDidMoveToSuperview, etc), and it can be hard to keep track of the correctness of your assumptions of what must have happened already.
In order to transfer the label successfully, you need both view1 and view2 to have been loaded. Since NSViewController's 'view' method causes the view to be loaded if necessary, you can be certain it's done *after* executing:
[self.view addSubview:viewController2.view];
since that references both views. Did you try putting the other line:
[viewController2.label2 setText:label1.text];
*after* the 'addSubview' line instead of before?
Is the label static in view1's NIB? If so, why can't you just use IB to put the same label text in view2 and have no code at all?
_______________________________________________
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