2012-02-09 16 views
5

W ten sposób wyświetlam otwarty panel jako ruchome okno.Arkusz NSOpenPanel

Czy ktoś może mi pomóc z uruchomieniem panelu jako arkusza? Obiekt window to mWindow. Znaczna część standardowego kodu, którego używam, jest amortyzowana.

NSOpenPanel *openPanel = [NSOpenPanel openPanel]; 
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"mp3", @"mp2", @"m4a", nil]; 

[openPanel setAllowsMultipleSelection: NO]; 
[openPanel setCanChooseDirectories:NO]; 
[openPanel setCanCreateDirectories:NO]; 
[openPanel setCanChooseFiles:YES]; 
[openPanel setAllowedFileTypes:fileTypes]; 

NSString * filePath = @"~/Desktop"; 
filePath = [filePath stringByExpandingTildeInPath]; 
NSURL *fileURL = [NSURL fileURLWithPath:filePath]; 
[openPanel setDirectoryURL:fileURL]; 

NSInteger clicked = [openPanel runModal]; 
if (clicked == NSFileHandlingPanelOKButton) { 
    for (NSURL *url in [openPanel URLs]) { 
     NSString *urlString = [url path]; 
     [input setStringValue:urlString]; 
     NSString *myString = [input stringValue]; 
     NSString *oldPath = [myString lastPathComponent]; 
     [inputDisplay setStringValue:oldPath]; 
    } 
} 

Odpowiedz

12

Całkiem proste, to właśnie tam w docs choć może zostały pominięte, ponieważ dana metoda jest faktycznie częścią NSSavePanel, z którego NSOpenPanel dziedziczy.

Zakładając jesteś kierowania irbis lub lepiej, a tym samym mają dostęp do bloków, to tylko kwestia zastąpienie runModal połączenia z tym:

[openPanel beginSheetModalForWindow:mWindow completionHandler:^(NSInteger result) { 

    if (result == NSFileHandlingPanelOKButton) { 

     // Do something. 
    } 
}]; 
+0

dzięki - wciąż nie może zdobyć. Otrzymuję błędy parsowania. – user1198008

+0

Proszę wyjaśnić, jakie błędy otrzymujesz. –

+0

Przepraszamy. Po prostu pominąłem inny * * po *]; Teraz działa dobrze. dzięki za pomoc. – user1198008