当我在我的iphone应用程序关闭时查看控制台时,似乎我的encodewithcoder被调用了两次。即使我只编码一次'NewsItems'数组。
这是正常的吗?
(void)encodeWithCoder:(NSCoder *)encoder {
NSLog(@"News encode called %@", self.title);
[encoder encodeObject:self.newsItemId forKey:KNewsItemNewsIdKey];
[encoder encodeObject:self.title forKey:KNewsItemTitleKey];
[encoder encodeObject:self.author forKey:KNewsItemAuthorKey];
[encoder encodeObject:self.description forKey:KNewsItemDescriptionKey];
[encoder encodeObject:self.imageUrl forKey:KNewsItemImageUrlKey];
[encoder encodeObject:self.thumbnailUrl forKey:KNewsItemThumbnailUrlKey];
[encoder encodeObject:self.createdAt forKey:KNewsItemCreatedAtKey];
//Images
//convert from PNG to NSData, other method available for JPG
NSData *savedImageData = UIImagePNGRepresentation(self.savedImage);
[encoder encodeObject:savedImageData forKey:KNewsItemSavedImageKey];
NSData *thumbnailImageData = UIImagePNGRepresentation(self.savedThumbnail);
[encoder encodeObject:thumbnailImageData forKey:KNewsItemSavedThumbnailKey];
}
//code to encode
[archiver encodeObject:self.newsArray forKey:KNewsArrayDataKey];
答案 0 :(得分:0)
在NSLog()
语句上放置一个断点并检查堆栈跟踪,看看每次都在给你打电话。