Re: noob: Question about senders and views
Re: noob: Question about senders and views
- Subject: Re: noob: Question about senders and views
- From: "Eric E. Dolecki" <email@hidden>
- Date: Wed, 8 Apr 2009 17:32:19 -0400
Sounds like I architected this poorly.
My views will all import a "model" class and then I can call methods in that
class to do things. Anything within my views I'll just handle there.
I'll have to check out the singleton. Thanks!
On Wed, Apr 8, 2009 at 4:37 PM, Brian Slick <email@hidden> wrote:
> I won't claim to have the concepts down, but I'll try to answer to the best
> of my understanding. Hopefully someone else will correct any mistakes that
> I make.
>
> FirstViewController and SecondViewController don't know anything about each
> other, because one did not create the other. So in order to communicate
> between them, you will have to involve a 3rd-party that knows about each
> one. In this case, your Application Delegate created the controller
> instances, so it will know about each of them. Also, depending on how
> complicated your program is going to be, you may want to read up on
> "Singletons", which provides a handy mechanism for having the data in a
> central location and still be accessible by other objects. Here is some
> more information on singletons:
> http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html
>
> I'm using a singleton in my own program, so I'll give some examples using
> that approach. I have created my own personal "DataController" class,
> configured it to act as a singleton, and have created a property called
> "theImportantText". In your first view controller, you would do something
> like this:
>
> #import "DataController.h"
>
> - (IBAction)buttonDown:(id)sender
> {
> DataController *dataController = [DataController sharedDataController];
>
> // Do whatever you do to create the text string
>
> [dataController setTheImportantText: @"hey there"];
> }
>
> Getting this information into the second view controller is along the same
> lines, but the specifics are determined by what exactly you want. Let's
> assume you want the label to already contain that string when the view
> appears. And assuming you have the label declared as an IBOutlet, you might
> do something like this:
>
> #import "DataController.h"
>
> - (void)viewWillAppear:(BOOL)animated
> {
> DataController *dataController = [DataController sharedDataController];
>
> [[self myLabel] setText:[dataController theImportantText]];
> }
>
> It would be a similar basic approach using the Application Delegate
> (YourAppNameAppDelegate.m).
>
> Hope this helps, or at least gets you pointed in the right direction. I
> wouldn't think of it so much as having the FirstViewController try to fire
> off a specific method in SecondViewController. I would think more in terms
> of finding the means to pass the data along, and just let the
> SecondViewController worry about how to handle that data.
>
> Brian
>
>
>
> On Apr 8, 2009, at 1:08 PM, Eric E. Dolecki wrote:
>
> I have a tab bar and it's driven by FirstViewController. I have a second
>> view with it's own xib. I can have buttons there call into a "buttonPress"
>> method I have in the FirstViewController. I am able to get the sender tag
>> easily.
>>
>> NSLog(@"id: %d", [sender tag] );
>>
>>
>> However in the second xib I have a text field that I want to populate with
>> a
>> string. Since the buttonPress method in the FirstViewController doesn't
>> know
>> about the UILabel in the SecondViewController, how can I have it set that
>> field?
>>
>> Eric
>> _______________________________________________
>>
>> 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
>>
>
> _______________________________________________
>
> 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
>
--
http://ericd.net
Interactive design and development
_______________________________________________
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