加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – (void)在Objective-C类静态变量构造函数中初始化

发布时间:2020-12-14 19:50:22 所属栏目:百科 来源:网络整理
导读:我从 here发现了一些示例代码. static UIImage *backgroundImageDepressed;/** * */@implementation DecimalPointButton+ (void) initialize { backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain];} 是这样的 – (v
我从 here发现了一些示例代码.

static UIImage *backgroundImageDepressed;

/**
 *
 */
@implementation DecimalPointButton

+ (void) initialize {
    backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain];
}

是这样的 – (void)initialize方法初始化目标c中的类(接口)的静态变量?我从来没有见过这个.

请你的指导.

提前感谢您分享您的知识.

萨加尔

解决方法

这个初始化方法在 The Objective-C Programming Language中有描述.

The runtime system sends an initialize message to every class object before the class receives any other messages and after its superclass has received the initialize message. This gives the class a chance to set up its runtime environment before it’s used. If no initialization is required,you don’t need to write an initialize method to respond to the message.

例如,当[DecimalPointButton alloc]被调用时,运行时将检查是否已经调用了[DecimalPointButton initialize].如果没有,它将初始化该类.这样可以确保在构建DecimalPointButton的任何实例之前,backgroundImageDepressed映像已准备就绪.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读