Re: Multiple Nib Question
Re: Multiple Nib Question
- Subject: Re: Multiple Nib Question
- From: Michael Ash <email@hidden>
- Date: Wed, 28 Jan 2009 23:49:00 -0500
On Wed, Jan 28, 2009 at 2:04 PM, Joseph Crawford <email@hidden> wrote:
> Hello Everyone,
>
> I had my project all working smooth using 1 nib file which contained my
> MainMenu and my window. I have since separated them because a lot of people
> suggested it. However this separation has led me to hit an issue.
>
> In my ManManu nib I have my App Delegate which then loads my window by
> instantiating the instance of my WindowController which displays the window.
>
> The issue is this. The application will copy sample files over to my
> application support directory (AppController) and also the SidebarController
> needs to be able to read this directory. I have the following method in my
> AppController
>
> - (NSString *)appSupportFolder {
>
> NSArray *paths =
> NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
> NSUserDomainMask, YES);
> NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] :
> NSTemporaryDirectory();
> return [basePath stringByAppendingPathComponent:@"TomTom POI Manager"];
> }
>
> As you can see this just determines the path to the users Application
> Support folder and returns that path.
>
> My issue is that this method is in the AppController class which is in my
> MainMenu nib. In my MainWindow nib I have a method that is trying to call
> the above method through an outlet to AppController, however since
> AppController is in another nib I cannot make the connection.
>
> What would be the best way to solve this issue?
>
> My thoughts are this.
>
> 1.) duplicate code across multiple nibs (not a good idea)
> 2.) create a class method (not sure this is the best answer either)
> 3.) in AppDelegate when the [[MainWindowController alloc] init] method is
> called, call initWithAppSupportPath:path so that the window controller gains
> knowledge of the path
Door #3 is the correct approach IMO, although it should simply be
-initWithPath:. The fact that you're saving to the App Support
directory should not influence the bulk of your program. Write it all
to accept arbitrary paths, then just hand it the App Support path from
the main controller at the beginning of your program. This makes your
design cleaner overall, especially if you should later change your
mind about where stuff should go.
In general, as much as possible, pass data around as parameters (or
obtain it from callbacks) rather than looking it up globally. It makes
your code more modular and cleaner.
Mike
_______________________________________________
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