macOS/iOS API解説

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

目次

alertStyle

INDEX>AppKit>NSAlert>

アラートスタイルを返します
@property NSAlertStyle alertStyle
var alertStyle: NSAlertStyle

解説

【NSAlertStyle】アラートスタイル
●NSWarningAlertStyle 注意パネル
●NSInformationalAlertStyle 情報パネル
●NSCriticalAlertStyle 警告パネル

enum NSAlertStyle : UInt {
    case WarningAlertStyle
    case InformationalAlertStyle
    case CriticalAlertStyle
}

返り値

( NSAlertStyle )

アラートスタイル

引数

フレームワーク

ApplicationKit

クラス

NSAlert

使用可能

10.3

編集時のバージョン

OS X 10.10

参照

例文

Objective-C

switch ([alert alertStyle]){
        case NSWarningAlertStyle:
            NSLog(@"NSWarningAlertStyle");
            break;
        case NSInformatio#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
//アラートパネルを作成
NSAlert *alert = [NSAlert alertWithMessageText:@"alertWithMessageText"
                defaultButton:@"defaultButton"
                alternateButton:@"alternateButton"
                otherButton:@"otherButton"
                informativeTextWithFormat:@"informativeTextWithFormat %@",@"text"
                ];
//ボタンを追加
[alert addButtonWithTitle:@"add"];
//
[alert setDelegate:delegateObject];
//ヘルプボタンをつける
[alert setShowsHelp:YES];
//シートで表示
[alert beginSheetModalForWindow:[sender window]
            modalDelegate:self
            didEndSelector:@selector(endAlert)
            contextInfo:nil
            ];
//アラートスタイルを表示
switch ([alert alertStyle]){
        case NSWarningAlertStyle:
            NSLog(@"NSWarningAlertStyle");
            break;
        case NSInformationalAlertStyle:
            NSLog(@"NSInformationalAlertStyle");
            break;
        case NSCriticalAlertStyle:
            NSLog(@"NSCriticalAlertStyle");
            break;
            }

}
//パネルが終わった時の処理
-(void)endAlert
{
NSLog(@"end");
}

@end
nalAlertStyle:
            NSLog(@"NSInformationalAlertStyle");
            break;
        case NSCriticalAlertStyle:
            NSLog(@"NSCriticalAlertStyle");
            break;
            }

Swift

//NSApplication alertStyle
    @IBAction func function004(sender: AnyObject) {
        //なにかモーダルがあっても終わり
        NSApp.abortModal()
        
        //テキストの作成
        let messageText:String = "Message text" as String
        let informativeText:String = "Information text" as String
        //NSAlertの作成
        let alert:NSAlert = NSAlert()
        alert.messageText = messageText
        alert.informativeText = informativeText
        alert.alertStyle = .CriticalAlertStyle
        let response:Int = alert.runModal()
        switch alert.alertStyle {
        case .WarningAlertStyle :
            NSLog("WarningAlertStyle")
            break
        case .InformationalAlertStyle :
            NSLog("InformationalAlertStyle")
            break
        case .CriticalAlertStyle :
            NSLog("CriticalAlertStyle")
            break
        default :
            break
        }
    }