windowWillBeginSheet:
ウインドウがシートを表示する時に呼び出されます
-(void)windowWillBeginSheet:(NSNotification *)aNotification:
解説
ウインドウがシートを表示する時に呼び出されます。NSBeginAlertSheetなどのアラートパネルの表示・表示終了に使います。シートがついている親ウインドウのデリゲートに実装します。
返り値
( void )
なし
引数
( NSNotification * )aNotification
通知
フレームワーク
ApplicationKit
クラス
NSWindow
Instance Methods
使用可能
10.0
参照
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { //デフォルトの通知センターをnCenterに NSNotificationCenter *nCenter =[NSNotificationCenter defaultCenter]; //通知を作る NSNotification *notifi = [NSNotification notificationWithName:@"NSWindowDidResizeNotification" object:nil]; //nCenterにオブザーバーを加える [nCenter addObserver:self//このオブジェクトを呼び出す selector:@selector(sheetOpen:) //呼び出されるメソッド name:@"NSWindowWillBeginSheetNotification" //シートウインドウが始まったら object:nil]; //nCenterにオブザーバーを加える [nCenter addObserver:self//このオブジェクトを呼び出す selector:@selector(sheetClose:) //呼び出されるメソッド name:@"NSWindowDidEndSheetNotification" //シートウインドウが終わったら object:nil]; /* 警告シートを表示します。 【title】 タイトル文字 【defaultButton】 デフォルトのボタン(右)(OKのボタンでよく使われる) 【alternateButton】 代理ボタン(左) 空の場合はボタンを作らない 【otherButton】 その他のボタン(中) 空の場合はボタンを作らない 【docWindow】 シートをつけるウインドウ 【modalDelegate】 デリゲート 【willEndSelector】 シートを終了しようとする時に実行するメソッド 【didEndSelector】 シート終了時に実行するメソッド 【contextInfo】 【msg】 メッセージ、printf書式を使うことができます。 */ //アラートパネルを表示する NSBeginAlertSheet( NSLocalizedString(@"title", @""), NSLocalizedString(@"OK", @""), NSLocalizedString(@"Cancel", @""), nil, [sender window], self, @selector(willEnd), @selector(sheetEnd), NULL, NSLocalizedString(@"msg", @"") ); } //シートがついている親ウインドウのデリゲート //シート開始 - (void)windowWillBeginSheet:(NSNotification *)notification { NSLog(@"windowWillBeginSheet"); } //シート終了 - (void)windowDidEndSheet:(NSNotification *)notification { NSLog(@"windowDidEndSheet"); } //NSWindowWillBeginSheetNotificationが通知されたときのメソッド - (void)sheetOpen:(NSNotification *)notification { NSLog(@"NSWindowWillBeginSheetNotification"); } //NSWindowDidEndSheetNotificationが通知されたときのメソッド - (void)sheetClose:(NSNotification *)notification { NSLog(@"NSWindowDidEndSheetNotification"); } //シートを閉じるときのメソッド - (void)willEnd { NSLog(@"willEnd"); } //シートを閉じたときのメソッド - (void)sheetEnd { NSLog(@"end"); } @end