Re: problems in runModal in NSOpenPanel used with defaults
Re: problems in runModal in NSOpenPanel used with defaults
- Subject: Re: problems in runModal in NSOpenPanel used with defaults
- From: Corbin Dunn <email@hidden>
- Date: Fri, 26 Sep 2008 10:18:07 -0700
Howdy spartan,
Oh! A few little tips:
On Sep 26, 2008, at 3:11 AM, spartan g wrote:
Hi,
I am writing an utility which needs to open a panel to browse files
and
select one.
- (IBAction)browseClicked:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
if ([panel runModal]) {
NSArray *filenames = [panel filenames];
NSString *filename = [filenames objectAtIndex:0];
Always check the array length first, or just use [panel filename];
if (filename){
printf("\n browseClicked: filename = %s \n", [filename cString]);
Just a side note: most cocoa people move to NSLog, but printf still
works. Try:
NSLog(@"%@", filename); -- much easier!
if ([appToOpenText stringValue] != NULL ){
nil is preferred to NULL.
[appToOpenText setStringValue: filename];
}
else printf("\n browseClicked: appToOpenText has NULL value \n");
}
else printf ("\n *** browseClicked: Filename is NULL *** \n");
}
}
The filename chosen is assigned to the textfield. I have used
defaults to
synchronize this filename and storing it in a pList file.
[_defaults setObject: [appToOpenText stringValue] forKey:
@"AppToOpen" ];
It seems strange to use the user defaults as your model to store
objects, but i'm sure there is a reason you do this.
[_defaults synchronize];
You probably don't want to hold onto the userdefaults instance as an
ivar, and instead always query it with [NSUserDefaults
standardUserDefaults]. It may be possible that something is calling
resetStandardUserDefaults, and blowing away the old instance.
corbin
_______________________________________________
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