我正在使用最新的 SDK 开发 iOS 应用。
我创建了一个继承自 UIView
的类,每次实例化该类时我都必须进行一些初始化。
我必须调用一个名为 setUpVars:
的方法,但我不知道在哪里向该方法发送消息:
- (id)initWithFrameCGRect)frame;
- (id)initWithCoderNSCoder*)aDecoder;
此类可以与自定义 xib 一起使用,或添加到 Storyboard,因此我需要确保在每种情况下都会调用该方法。
- (void)setUpVars
{
_preferenceKey = @"";
_preferenceStatus = NO;
_isDown = NO;
}
我必须在哪里添加 [self setUpVars];
?
基本上你会想要涵盖这两种情况
- (id)initWithFrameCGRect)frame;
{
self = [super initWithFrame:frame];
if (self) {
[self setUpVars];
}
return self;
}
- (id)initWithCoderNSCoder *)aDecoder;
{
self = [super initWithCoder:aDecoder];
if (self) {
[self setUpVars];
}
return self;
}
关于ios - 具有自定义初始化的自定义 UIView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15357181/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |