macOS/iOS API解説

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

目次

beginSheetModalForWindow:completionHandler:

INDEX>AppKit>NSAlert

アラートシートを表示します

Swift

func beginSheetModalForWindow(_ sheetWindow: NSWindow,
            completionHandler handler: ((NSModalResponse) -> Void)?)

Objective-C

- (void)beginSheetModalForWindow:(NSWindow *)sheetWindow
               completionHandler:(void (^)(NSModalResponse returnCode))handler

解説

アラートシートを表示します。
モーダルで使用する場合にはこのメソッドを使用します。

返り値

なし

引数


フレームワーク

ApplicationKit

クラス

NSAlert

使用可能

10.9-

編集時のバージョン

OS X 10.10

参照

関連記事(外部サイト)

例文

Swift

    //NSAlert beginSheetModalForWindow:completionHandler:
    @IBAction func function010(sender: AnyObject) {
        //なにかモーダルがあっても終わり
        NSApp.abortModal()
        
        //テキストの作成
        let messageText:String = "Message text" as String
        let informativeText:String = "Information text" as String
        //NSAlertの作成
        let alert:NSAlert = NSAlert()
        alert.alertStyle = .WarningAlertStyle
        alert.messageText = messageText
        alert.informativeText = informativeText
        //1つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Stop", comment:""))
        //2つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Continue", comment:""))
        alert.delegate = self
        //シートを出す
        alert.beginSheetModalForWindow(window) { responseCode in
            if NSAlertSecondButtonReturn == responseCode {
                NSLog("SecondButton")
            }
        }
        

    }