NSCoder *coder;
coder=[[NSCoder alloc]init];
[coder encodeObject:@"value" forKey:@"frame"];
由于未捕获的异常终止应用程序&#39; NSInvalidArgumentException&#39;,原因:&#39; *** -encodeObject:forKey:无法发送到类NSCoder的抽象对象:创建一个具体的实例!`< / p>
这在运行时间中断了。任何人都帮我找到它我做错了什么?
答案 0 :(得分:-2)
需要创建一个模型类,并且在这个模型类中,需要实现一个NSCodingProtocol
例如Book Class
Book.h
@interface Book : NSObject<NSCoding>
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *author;
@end
Book.m
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
self.title = [aDecoder decodeObjectForKey:@"name"];
self.author = [aDecoder decodeObjectForKey:@author"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:_name forKey:@"name"];
[aCoder encodeObject:_author forKey:@"author"];
}