abortModal
イベントループを中断します
解説
runModalForWindow: や runModalSession:によって起動したイベントループを中断します。
このメソッドで中断されたときにrunModalForWindow: や runModalSession:にNSRunAbortedResponseが返されます。
【NSRunAbortedResponse】
●NSRunStoppedResponse
●NSRunAbortedResponse
●NSRunContinuesResponse
enum { NSModalResponseStop = (-1000), NSModalResponseAbort = (-1001), NSModalResponseContinue = (-1002), }; typedef NSInteger NSModalResponse;
Objective-Cではenumが規定されていますが、Swiftでは整数が返されます。
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 }
返り値
( void )
なし
引数
フレームワーク
ApplicationKit
クラス
NSApplication
Instance Methods
使用可能
10.0
例文
#import "Controller.h" @implementation Controller - (IBAction)pushButton:(id)sender { //モーダルにする NSInteger result=[[NSApplication sharedApplication] runModalForWindow:panel]; //ここでいったん処理は止まってる //モーダルが解除されたら戻ってくる switch (result) { case NSRunStoppedResponse: NSLog(@"NSRunStoppedResponse %d",result); break; case NSRunAbortedResponse: NSLog(@"NSRunAbortedResponse %d",result); break; case NSRunContinuesResponse: NSLog(@"NSRunContinuesResponse %d",result); break; default: break; } } - (IBAction)stopModal:(id)sender { //モーダルやめる [NSApp abortModal]; } @end
//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) }