macOS/iOS API解説

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

目次

preventsApplicationTerminationWhenModal

INDEX>AppKit> NSWindow

ウインドウがモーダルの時に、終了を防ぐかどうか

Objective-C

@property BOOL preventsApplicationTerminationWhenModal

Swift

var preventsApplicationTerminationWhenModal: Bool

解説

このウインドウがモーダルの時に、アプリケーションの終了を出来ないようにするかどうかの設定

trueの場合の挙動 終了できない。


falseの場合の挙動 終了できる

設定値

Objective-C

BOOL

Swift

Bool

クラス

NSWindow

使用可能

10.6

参照

関連記事(外部サイト)


Close button is deactivated even if sheet has preventsApplicationTerminationWhenModal = NO · Issue #112 · indragiek/INAppStoreWindow · GitHub

例文

Objective-C

Swift

    //NSWindow preventsApplicationTerminationWhenModal
    func abortTimer019(timer:NSTimer!) {
        NSLog("abort modal")
        let anApplication = NSApplication.sharedApplication()
        var p :MyPanel = timer.userInfo?.objectForKey("panel") as MyPanel
        if (p.worksWhenModal){
            NSLog("panel worksWhenModal YES")
        }else{
            NSLog("panel worksWhenModal NO")
        }
        NSLog("%@",p.title!)
        p.orderOut(self)
        
        //modal stop
        anApplication.abortModal()
    }
    @IBAction func function019(sender: AnyObject) {
        var panel : MyPanel = MyPanel(
            contentRect: NSMakeRect(0.0, 0.0, 300, 200),
            styleMask:  NSTitledWindowMask |
                NSClosableWindowMask |
                NSMiniaturizableWindowMask |
            NSResizableWindowMask,
            backing: .Buffered,
            defer: false)
        windowArray.addObject(panel) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        panel.preventsApplicationTerminationWhenModal = true //終了できない
        //panel.preventsApplicationTerminationWhenModal = false //終了できる
        
        panel.center()//ウインドウをスクリーンの中心に
        panel.title = "ウインドウタイトル"//タイトル設定
        //text field
        var textField : NSTextField = NSTextField(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0))
        panel.contentView.addSubview(textField)
        panel.orderFront(self)//前面に
        //タイマー
        var timer = NSTimer.scheduledTimerWithTimeInterval(30.0, target: self, selector: Selector("abortTimer019:"), userInfo: ["panel":panel], repeats: false)
        
        //タイマー、モーダルに入るとタイマーが動かなくなるので、ランループに追加する
        NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
        
        
        let anApplication = NSApplication.sharedApplication()
        //モーダル開始
        var result:NSModalResponse = anApplication.runModalForWindow(panel)
    }

更新時のバージョン

OS X 10.10