Sag*_*ari 10 iphone xcode constructor interface objective-c
我从这里找到了一些示例代码.
static UIImage *backgroundImageDepressed;
/**
*
*/
@implementation DecimalPointButton
+ (void) initialize {
backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain];
}
Run Code Online (Sandbox Code Playgroud)
它是这样的 - +(void) initialize方法初始化Objective C中的类(接口)的静态变量?我以前从未见过这个.
ken*_*ytm 17
该+initialize方法在Objective-C编程语言中描述.
运行时系统在类接收任何其他消息之前以及在其超类已收到 消息之后
initialize向每个类对象发送消息.这使类有机会在使用之前设置其运行时环境.如果不需要初始化,则无需编写方法来响应消息.initializeinitialize
例如,[DecimalPointButton alloc]调用时,运行时将检查是否[DecimalPointButton initialize]已调用.如果没有,那+initialize就是全班.这可确保在构造DecimalPointButton的任何实例之前backgroundImageDepressed图像已准备就绪.