macOS/iOS API解説

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

目次

NSModalResponse

INDEX>AppKit>NSApplication

モーダルの結果

Objective-C

enum {
   NSModalResponseStop                 = (-1000),
   NSModalResponseAbort                = (-1001),
   NSModalResponseContinue             = (-1002),
};
typedef NSInteger NSModalResponse;

Swift

typealias NSModalResponse = Int

解説

モーダルの結果

フレームワーク

ApplicationKit

クラス

NSApplication

使用可能

10.9

更新時のバージョン

OS X 10.10

関連記事(外部サイト)

例文

    //NSApplication abortModal
    //時間が来たらモーダルを停止する
    func abortTimer(timer:NSTimer!) {
        NSLog("abort modal")
        let anApplication = NSApplication.sharedApplication()
        //modal
        anApplication.abortModal()
    }
    
    @IBAction func function011(sender: AnyObject) {
        NSLog("abortModal")
        let anApplication = MyApplication.sharedApplication()
        
        var timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: Selector("abortTimer:"), userInfo: nil, repeats: false)

        //タイマー、モーダルに入るとタイマーが動かなくなるので、ランループに追加する
        NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)

        //モーダル開始
        var result:NSModalResponse = anApplication.runModalForWindow(newWindow)
        
        //モーダルが閉じられた場合の結果が帰ってくる
        switch result {
        case -1000 :    //NSModalResponseStop
            NSLog("NSModalResponseStop")
            break
        case -1001 :    //NSModalResponseAbort
            NSLog("NSModalResponseAbort")
        case -1002 :
            NSLog("NSModalResponseContinue")
        default :
            break
        }
        //帰ってきたらウインドウ閉じる
        newWindow.orderOut(self)
    }