Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 何时使用initWithCoder:方法?_Iphone_Iphone Sdk 3.0_Ios4 - Fatal编程技术网

Iphone 何时使用initWithCoder:方法?

Iphone 何时使用initWithCoder:方法?,iphone,iphone-sdk-3.0,ios4,Iphone,Iphone Sdk 3.0,Ios4,什么时候应该使用initWithCoder:方法?当您处理已存档的对象时,应该使用initWithCoder:方法。例如,当您专门使用nskeyedunachiver创建这些存档对象时,或者当您需要向来自xib文件的对象添加自定义初始化代码时。是,如果您在IB中使用自定义类,则这些对象将使用initWithCode:方法实例化。因此,在您的类中,您将覆盖: -(id) initWithCoder:(NSCoder*)aDecoder { if (! (self = [super init

什么时候应该使用initWithCoder:方法?

当您处理已存档的对象时,应该使用
initWithCoder:
方法。例如,当您专门使用
nskeyedunachiver
创建这些存档对象时,或者当您需要向来自xib文件的对象添加自定义初始化代码时。

是,如果您在IB中使用自定义类,则这些对象将使用
initWithCode:
方法实例化。因此,在您的类中,您将覆盖:

-(id) initWithCoder:(NSCoder*)aDecoder {
    if (! (self = [super initWithCoder:aDecoder]))
        return nil;

    // object has been created from IB... do initialization stuff here

    return self;
}

我问这个问题的原因是因为我已经创建了UIScrollView的一个子类,我想将它设置在xib中的位置,获取该信息并使用它来设置子类,我会使用initWithCoder:进行类似的设置吗?