• 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: NSOpenPanel instantly closing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSOpenPanel instantly closing
      • From: Nick Forge <email@hidden>
References: 
 >NSOpenPanel instantly closing (From: Nick Forge <email@hidden>)

  • Prev by Date: multi-document-type NSDocument-based app
  • Next by Date: Re: NSOpenPanel instantly closing
  • Previous by thread: Re: NSOpenPanel instantly closing
  • Next by thread: Re: NSOpenPanel instantly closing
  • Index(es):
    • Date
    • Thread