NSButtonCell
The NSButtonCell class is a subclass of NSActionCell. An NSButtonCell object defines the user interface of a button, checkbox(switch), radio button, and any other clickable region of a view. For example, the NSButton subclass of NSControl uses a single NSButtonCell object to implement its user interface. The configuration of the NSButtonCell object controls how the NSButton object appears and behaves but the NSButton object is what sends a message when clicked.
NSButtonCell类是NSActionCell类的子类。NSButtonCell对象定义了一个可与用户交互的界面,这个可交互的区域可以是一个按钮,复选框,单选框,或者视图上任何可点击的区域。例如,NSButton类,它是NSControl的子类,仅通过一个NSButtonCell对象就实现了与用户的交互。NSButtonCell类的特性影响了NSButton类的外观及动作状态,NSButton类所做的就是在接受到点击事件时,发送消息。
Overview
Setting the integer, float, double, or object value of an NSButtonCell object results in a call to state with the value converted to integer. In the case of objectValue, nil is equivalent to 0, and a non-nil object that doesn't respond to intValue sets the state to 1. Otherwise the state is set to the object's intValue. Similarly, for most button types, querying the integer, float, double, or object value of an NSButtonCell returns the current state in the requested representation. In the case of objectValue, this is an NSNumber containing YES for on, NO for off, and integer value -1 for the mixed state. For accelerator buttons (type NSAcceleratorButton or NSMultiLevelAcceleratorButton) on systems that support pressure sensitivity, querying doubleValue returns the amount of pressure applied while pressing the button.
给NSButtonCell对象设置一个整数值、小数、浮点数或任何一种类型数值,它都会先将这个值转换为一个整数,再用这个整数值来表示NSButtonCell对象的状态。对于参数值,nil类型的值相当于0,一个非nil的类型并不代表其值为1。另外,对象设置的整数值是多少,就会被设置成什么状态。相似地,对于大多数类型的button,通过查询一个NSButtonCell对象的整数值、小数、浮点数或其它值,返回这个button当前所要求设定的状态。这个整数值,是一个NSNumber类,YES表示开启状态,NO表示关闭状态,-1表示混合状态。对于系统里的一些加速器类的button(如NSAcceleratorButton 或 NSMultiLevelAcceleratorButton),它们具有压力灵敏度,当在压力作用于其上时,查询它们的浮点值,会返回当前作用的压力值。
For more information on the behavior of NSButtonCell, see the NSButton and NSMatrix class specifications, and Button Programming Topics.
想要查询更多关于NSButtonCell类的动作属性信息,可以查看NSButton类和NSMatrix类的特性,和Button Programming Topics。
Exceptions
In its implementation of the compare: method (declared in NSCell), NSButtonCell raises an NSBadComparisonException if the otherCell argument is not of the NSButtonCell class.
异常信息
在其中的一个compare实现方法里,如果传入的otherCell参数不是NSButtonCell类的话,NSButtonCell类会抛出一个NSBadComparisonException类的异常。
func - (NSComparisonResult)compare:(id)otherCell;