• 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: EXC_BAD_ACCESS when calling NSOpenPanel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: EXC_BAD_ACCESS when calling NSOpenPanel
      • From: Jens Alfke <email@hidden>
References: 
 >EXC_BAD_ACCESS when calling NSOpenPanel (From: Darren Wheatley <email@hidden>)

  • Prev by Date: Re: NSURLConnection retaining delegate?
  • Next by Date: UIImageView Animation Question
  • Previous by thread: Re: EXC_BAD_ACCESS when calling NSOpenPanel
  • Next by thread: Re: EXC_BAD_ACCESS when calling NSOpenPanel
  • Index(es):
    • Date
    • Thread