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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com