Re: EXC_BAD_ACCESS when calling NSOpenPanel
Re: EXC_BAD_ACCESS when calling NSOpenPanel
- Subject: Re: EXC_BAD_ACCESS when calling NSOpenPanel
- From: Ken Thomases <email@hidden>
- Date: Wed, 25 Nov 2009 17:25:53 -0600
On Nov 23, 2009, at 6:51 PM, Darren Wheatley wrote:
> I have the following code as the action from a button click:
>
> - (IBAction)chooseFile:(id)sender;
> {
> NSOpenPanel *openPanel = [NSOpenPanel openPanel];
You haven't retained this panel. If you want this object to live beyond the current autorelease context, you need to retain it. (Note that not retaining doesn't guarantee that it _will_ be released at the end of the autorelease context, just that it might.)
> [openPanel setCanChooseDirectories:NO];
> [openPanel setCanCreateDirectories:NO];
> [openPanel beginSheetForDirectory:nil
> file:nil
> types:[NSArray arrayWithObject:@"txt"]
> modalForWindow:window
> modalDelegate:self
> didEndSelector:@selector(fileOpenDidEnd:returnCode:context:)
> contextInfo:nil];
> }
>
> - (void)fileOpenDidEnd:(NSOpenPanel*)openPanel
> returnCode:(NSInteger)code
> context:(void*)context
> {
> if (code == NSCancelButton) return;
> [self setFilePath:[openPanel filename]];
> [filePathField setStringValue:[openPanel filename]];
> }
Regards,
Ken
_______________________________________________
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