を閉じていない私は、カスタムのモーダルダイアログボックスを表示しようとし、それを次のようにやっている:モーダルカスタムシート
EncPasswordSheetはIBOutlet NSWindowの*型です。
@implementation EncryptionPasswordSheet
-(id)init
{
return self;
}
- (void)showCustomDlg:(NSWindow *)window
{
if (!EncPasswordSheet)
{
[NSBundle loadNibNamed: @"EncryptionPasswordDlg" owner: self];
}
[NSApp beginSheet:EncPasswordSheet modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil];
[NSApp runModalForWindow: EncPasswordSheet];
[NSApp endSheet: EncPasswordSheet];
[EncPasswordSheet orderOut: self];
}
- (IBAction)getPasswordFromSheet:(id)sender
{
password = [passwordField stringValue];
[NSApp stopModal];
}
- (IBAction)cancelEncPasswordSheet:(id)sender
{
password = nil;
[NSApp stopModal];
}
@end
ダイアログボックスが表示され、入力されます。 「OK」または「キャンセル」を押すと、それぞれのIBActionメソッドが実行され、プログラムが続行されます。問題は、ダイアログボックスが途切れていないことです。つまり、閉じていないか消えているということです。
- (void)showCustomDlg:(NSWindow *)window {
if (!EncPasswordSheet) {
[NSBundle loadNibNamed: @"EncryptionPasswordDlg" owner: self];
}
[NSApp beginSheet:EncPasswordSheet
modalForWindow:window modalDelegate:nil
didEndSelector:nil contextInfo:nil];
}
- (IBAction)getPasswordFromSheet:(id)sender {
password = [passwordField stringValue];
[EncPasswordSheet orderOut: self];
[NSApp endSheet: EncPasswordSheet];
}
- (IBAction)cancelEncPasswordSheet:(id)sender {
password = nil;
[EncPasswordSheet orderOut: self];
[NSApp endSheet: EncPasswordSheet];
}
コードを少し分かりやすくするために、コードを再フォーマットすることをお勧めします。 4つのスペースでインデントして、テキストとしてコードを書式設定します。 – jergason