| Home 目次>ApplicationKit>NSAlert | 10.3 |
beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:
シートでアラートパネルを表示します。
-(void) beginSheetModalForWindow:(NSWindow *)window
modalDelegate:(id)delegate
didEndSelector:(SEL)didEndSelector
contextInfo:(void *)contextInfo
【返り値】 | |
| void | なし |
| 【パラメータ】 | |
| window | |
| delegate | デリゲート |
| didEndSelector | シート終了時に実行するメソッド |
| contextInfo | 追加情報 |
【解説】
シートでアラートパネルを表示します。
パネルの終了時のために- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo;
{}
というメソッドを使います。
returnCodeに押されたボタンの番号が戻されてきますのでそのコードをもとに分岐処理します。追加情報はcontextInfoを使って渡します。
【returnCode】
-1 その他のボタン
0 キャンセルボタン
1 デフォルトボタン
【例文】
#import "MyObject.h"
@implementation MyObject
- ( IBAction )myAction:( id )sender
{
NSAlert *alert = [NSAlert alertWithMessageText: @"alertWithMessageText"
defaultButton: @"defaultButton"
alternateButton: @"alternateButton"
otherButton: @"otherButton"
informativeTextWithFormat: @"informativeTextWithFormat %@" , @"text"
];
[alert beginSheetModalForWindow:[sender window]
modalDelegate: self
didEndSelector: @selector ((alertDidEnd:returnCode:contextInfo:)
contextInfo: nil
];
}
- ( void )alertDidEnd:(NSAlert *)alert returnCode:( int )returnCode contextInfo:( void *)contextInfo;
{
NSLog( @"%d" ,returnCode);
[ self replyToShouldUnselect: YES ];
}
@end
![]() | |
この記事を評価してください。
| Home 目次>ApplicationKit>NSAlert | 修正日2007.5.28 |