1

所以,我有一个正在序列化并存储在文件中的视图。在该视图中,有n个子类 UILabel,唯一的区别是活动属性。我在 UILabel 子类中有 initwithcoder 和 encodewithcoder,但我仍然无法在标签中获取自定义变量。我已经包含了我的子类的方法和以下内容。任何帮助表示赞赏。

自定义UILabel:

- (id) initWithCoder:(NSCoder *)decoder
{
    self = [super initWithCoder:decoder];

    if (self != nil) {
        self.live = [decoder decodeBoolForKey:@"live"];
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeBool:self.live forKey:@"live"];
}

因为我只是取消归档包含标签的视图,所以我假设 ios 不会取消归档自定义标签?

谢谢

4

1 回答 1

0

您错过了对 的呼叫[super encodeWithCoder:aCoder]。这将导致一个不正确的序列化对象,我不确定后果是什么,但您似乎已经找到了其中之一!

于 2011-12-19T12:21:09.397 回答