macOS/iOS API解説

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

目次

defaultButtonCell

INDEX>AppKit> NSWindow

デフォルトボタンセルを返します

Objective-C

- (NSButtonCell *)defaultButtonCell

Swift

func defaultButtonCell() -> NSButtonCell?

解説

デフォルトボタンセル(ウインドウがReturn(またはEnter)キーイベントを受け取った時実行されるボタンセル)を返します。

f:id:jjj777:20150404072122p:plain

返り値

ボタンセル
Objective-C

(NSButtonCell *)

Swift

NSButtonCell?

引数

フレームワーク

ApplicationKit

クラス

NSWindow

使用可能

10.0

参照

- setDefaultButtonCell:
- disableKeyEquivalentForDefaultButtonCell
- enableKeyEquivalentForDefaultButtonCell

更新時のバージョン

OS X 10.10

関連記事(外部サイト)

例文

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
NSButtonCell *bCell = [myWindow defaultButtonCell];

[bCell setTitle:@"1"];
}

@end

Swift

    //NSWindow setDefaultButtonCell
    //NSWindow defaultButtonCell
    func buttonAction088_a(sender: AnyObject){
        var aWindow : NSWindow = (sender as NSButton).window!
        NSLog("type A")
    }
    func buttonAction088_b(sender: AnyObject){
        var aWindow : NSWindow = (sender as NSButton).window!
        NSLog("type B")
    }
    @IBAction func function088(sender: AnyObject) {
        var theWindow : MyWindow082 = MyWindow082(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false)
        windowArray.addObject(theWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        
        
        theWindow.center()//ウインドウをスクリーンの中心に
        theWindow.title = "ウインドウタイトル"//タイトル設定
        theWindow.orderFront(self)//前面に
        theWindow.makeKeyAndOrderFront(self)//表示
        
        
        //ボタンを作成
        var theButton1 : NSButton = NSButton(frame: NSMakeRect(50.0, 2.0, 100.0, 30.0))
        theButton1.title = "Type A"
        theButton1.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton1.action = Selector("buttonAction088_a:")
        theButton1.target = self
        theWindow.contentView.addSubview(theButton1)
        
        //ボタンを作成
        var theButton2 : NSButton = NSButton(frame: NSMakeRect(150.0, 2.0, 100.0, 30.0))
        theButton2.title = "Type B"
        theButton2.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton2.action = Selector("buttonAction088_b:")
        theButton2.target = self
        theWindow.contentView.addSubview(theButton2)
        
        //デフォルトボタンにする
        theWindow.setDefaultButtonCell(theButton2.cell() as? NSButtonCell)
        let aCell : NSButtonCell = theWindow.defaultButtonCell()!

        NSLog("%@",aCell.title)
        
        var textField1 : NSTextField = NSTextField(frame: NSMakeRect(100.0, 100.0, 100.0, 30.0))
        theWindow.contentView.addSubview(textField1)
    }