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