2012-02-09 4 views
5

これは、オープンパネルをフローティングウィンドウとして表示する方法です。NSOpenPanelシート

誰かがシートとしてパネルを使用して私を助けることができますか?ウィンドウオブジェクトはmWindowです。私が使用していた標準コードの多くは価値が下がっています。

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]; 
    } 
} 

答えて

12

かなりシンプルな、それは、関連する方法は、実際にNSOpenPanelが継承するNSSavePanel、の一部であるため、あなたがそれを見逃しているかもしれませんが、ドキュメントにすぐそこです。あなたはSnow Leopardのをターゲットまたはより良いので、ブロックへのアクセス権を持っている、それはこれであなたのrunModalコールを交換するだけの問題だと仮定

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

    if (result == NSFileHandlingPanelOKButton) { 

     // Do something. 
    } 
}]; 
+0

ありがとう - まだそれを得ることができません。解析エラーが発生しています。 – user1198008

+0

どのようなエラーが発生しているのか説明してください。 –

+0

申し訳ありません。私は単純に別の} * after *を省略していました。今はうまくいく。助けてくれてありがとう。 – user1198008

関連する問題