Re: NSOpenPanel instantly closing
Re: NSOpenPanel instantly closing
- Subject: Re: NSOpenPanel instantly closing
- From: Keith Duncan <email@hidden>
- Date: Sun, 18 Feb 2007 11:35:42 +0000
- (IBAction)open:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
// Run the open panel
[panel beginSheetForDirectory:nil
file:nil
types:[NSImage imageFileTypes]
modalForWindow:[stretchView window]
modalDelegate:self
didEndSelector:
@selector(openPanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
Might I suggest that stretchView is a nil pointer? That would cause
the behavior you are seeing.
In order to deal with the situation of the modalForWindow: argument
being a nil pointer you must bear in mind that [NSOpenPanel openPanel]
returns an autoreleased object, and since you aren't starting a modal
run loop inside that method of yours it gets released pretty quickly.
The solution is to retain the open panel in your open: method and
release it in the openPanelDidEnd:returnCode:contextInfo: method.
Alternatively you could do something like this *typed in mail*
- (IBAction)open:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
// The method will block here until the user clicks a button
if ([panel runModalForDirectory:nil file:nil types:[NSImage
imageFileTypes]] == NSOkButton) {
NSArray *filenames = [panel filenames];
// Do something with the filenames here
}
}
- Keith
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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