macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:

シートでアラートパネルを表示します。
-(void)beginSheetModalForWindow:(NSWindow *)window:
             modalDelegate:(id)delegate:
             didEndSelector:(SEL)didEndSelector:
             contextInfo:(void *)contextInfo:

解説

シートでアラートパネルを表示します。
パネルの終了時のために- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo;
{}
というメソッドを使います。
returnCodeに押されたボタンの番号が戻されてきますのでそのコードをもとに分岐処理します。追加情報はcontextInfoを使って渡します。
【returnCode】

  • 1 その他のボタン

0 キャンセルボタン
1 デフォルトボタン

返り値

( void )

なし

引数

( NSWindow * )window
( id )delegate

デリゲート

( SEL )didEndSelector

シート終了時に実行するメソッド

( void * )contextInfo

追加情報

フレームワーク

ApplicationKit

クラス

NSAlert

Instance Methods

使用可能

10.3

参照

-runModal

例文

#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