• 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 runModal on a dispatch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOpenPanel runModal on a dispatch


  • Subject: Re: NSOpenPanel runModal on a dispatch
  • From: Rob Petrovec <email@hidden>
  • Date: Sun, 16 Dec 2012 15:10:22 -0800

On Dec 16, 2012, at 9:05 AM, Mike Abdullah <email@hidden> wrote:

>
> On 16 Dec 2012, at 10:45, Tamas Nagy wrote:
>
>> Hey,
>>
>> I'm trying to display an NSOpenPanel on a dispatch, with half-luck. The panel displays, but no files going to be displayed - the circle just spinning on the bottom-left corner. Anyone have an idea what going wrong?
>>
>> Thanks,
>>
>> Tamas
>>
>>   dispatch_async(dispatch_get_main_queue(), ^{
>>
>>       NSOpenPanel *oPanel = [NSOpenPanel openPanel];
>>
>>       NSMutableArray *filetype = [NSMutableArray arrayWithCapacity:0];
>>
>>       [filetype insertObject:@"txt" atIndex:0];
>>
>>       [oPanel setAllowedFileTypes:filetype];
>>       [oPanel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]];
>
> This line of code is your problem. +URLWithString: is not an appropriate way to create a URL from a path. +fileURLWithPath:isDirectory: is what you want instead.
>
> +[NSSavePanel setDirectoryURL:] behaves oddly with non-existing paths, as covered at http://www.mikeabdullah.net/pre-populating-nssavepanel.html

	On 10.7.4 (or there abouts) and up -setDirectoryURL will spew in the console if you pass it a non-file URL or a nonexistent URL.  It must have the “file://“ scheme.  It will also spew out the directory it will use instead, which is usually the directory the user last visited with the app, the last valid directory passed to -setDirectoryURL:, or ~/Documents..  The spew would be something like this:

> Invalid URL passed to an open/save panel: '/Users/rob/Desktop'.  Using 'file:///Users/rob/Documents/' instead

—Rob



_______________________________________________

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


References: 
 >NSOpenPanel runModal on a dispatch (From: Tamas Nagy <email@hidden>)
 >Re: NSOpenPanel runModal on a dispatch (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: NSOpenPanel runModal on a dispatch
  • Next by Date: Re: NSOpenPanel runModal on a dispatch
  • Previous by thread: Re: NSOpenPanel runModal on a dispatch
  • Next by thread: Re: NSOpenPanel runModal on a dispatch
  • Index(es):
    • Date
    • Thread