15
我知道,当你写一个实现NSCoding的对象的子类的initWithCoder方法时,你必须调用超级initWithCoder
(而不是super init
),但是我必须在执行encodeWithCoder时调用super encodeWithCoder
?子类化实现NSCoding的对象时是否需要调用[super encodeWithCoder]?
我知道,当你写一个实现NSCoding的对象的子类的initWithCoder方法时,你必须调用超级initWithCoder
(而不是super init
),但是我必须在执行encodeWithCoder时调用super encodeWithCoder
?子类化实现NSCoding的对象时是否需要调用[super encodeWithCoder]?
如果从支持编码类继承,所以一般adviseable在encodeWithCoder:
方法使用[super encodeWithCoder:]
,尽可能[super initWithCoder:]
在initWithCoder:
方法中使用。
文档:NSCoding Protocol Reference
参考:http://www.cocoadev.com/index.pl?NSCoder
如果类从符合 (NSObject的不符合),那么你应该包括一个类继承的[encodeWithCoder:]方法。
// <NSCoding> protocol methods
-(void)encodeWithCoder:(NSCoder*)coder
{
[super encodeWithCoder:coder];
/*
[coder encodeObject: theNSStringInstanceVariable];
[coder encodeObject: theNSDictionaryInstanceVariable];
[coder encodeValueOfObjCType:@encode(BOOL) at:&theBooleanInstanceVariable];
[coder encodeValueOfObjCType:@encode(float) at:&theFloatInstanceVariable];
*/
}
谢谢了很多:) – XaitormanX 2012-04-06 08:53:26
@XaitormanX欢迎你,我的朋友! :-) – 2012-04-06 08:54:33