Mac アプリケーション プログラミングは初めてです。システムからファイルを選択するために NSOpenPanel を使用しています。ファイルを選択してキャンセル/開くボタンを押すと、completedHandler ブロックが実行されます。
OpenPanel ウィンドウを閉じると、次の問題に直面しています。
- mainAppWindow.visible の結果が 1 であっても、メイン アプリケーション ウィンドウも閉じられます。
- また、メイン アプリ ウィンドウのウィンドウ クローズ デリゲート メソッドを受け取りません。
NSOpenPanel の作成に使用したコード スニペットを以下に示します。
-(void)openFile
{
//this gives you a copy of an open file dialogue
NSOpenPanel*openPanel = [NSOpenPanel openPanel];
//set the title of the dialogue window
openPanel.title = @"Choose a .zip formate file";
//shoud the user be able to resize the window?
openPanel.showsResizeIndicator = NO;
//should the user see hidden files (for user apps - usually no)
openPanel.showsHiddenFiles = NO;
//can the user select a directory?
openPanel.canChooseDirectories = NO;
//can the user create directories while using the dialogue?
openPanel.canCreateDirectories = NO;
//should the user be able to select multiple files?
openPanel.allowsMultipleSelection = NO;
//an array of file extensions to filter the file list
openPanel.allowedFileTypes = @[@"zip"];
[openPanel beginWithCompletionHandler:^(NSInteger result) {
//if the result is NSOKButton
//the user selected a file
if (result==NSModalResponseOK) {
//Do something
}
else if (result== NSModalResponseCancel)
{
//do something
}
}];
}