• 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 14:58:04 -0500

I hope I am replying correctly, I am new at this.

The text in label1 is set with the setText method when the view is loaded.

What I am trying to achieve is putting some text whose value is in a label on view1 into a label on view2 (called label2).  I was hoping to do with with something like…

[label2 setText:<the text from label1 on view1>;

of course this code would be going in viewController2 .

The objects are all created in NIB files.  The labels do not need to be dynamically linked. I just need this done when the view is loaded with the addSubview method.

As for which views and controllers are aware of or have references to other views and controller, well that is the issue.  I don't know how to reference an object on a view outside of the view controller I am working in.  Surely there must be a way to do this.

Steve



On Sep 21, 2010, at Sep 21:2:27 PM, Quincey Morris wrote:

> On Sep 21, 2010, at 11:57, 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?
>
> Probably no one can advise you on the *best* way to do this without knowing exactly what you're trying to achieve. (Are there NIB files involved? How is the label initialized in view1? Does the label change during execution in such a way that view2 must be dynamically updated to match view1? Which views and controllers are aware of -- have references to -- the other views and controllers?)
>
> The answer probably involves making the text value of the label a property of viewController1, and propagating it to the other places via bindings, KVO or setting via outlets.
>
>

_______________________________________________

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

References: 
 >Access object from another view (From: Steve Wetzel <email@hidden>)
 >Re: Access object from another view (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Access object from another view
  • Next by Date: Re: Access object from another view
  • Previous by thread: Re: Access object from another view
  • Next by thread: Re: Access object from another view
  • Index(es):
    • Date
    • Thread