我有这样一个genearl对象:
·H
@interface Object : NSObject{
NSNumber *iden;
NSString *name;
NSString *address;
}
@property (nonatomic, retain) NSNumber *iden;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *address;
@end
的.m
@implementation Object
@synthesize name;
@synthesize iden;
@synthesize address;
- (id) initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self) {
self.iden = [aDecoder decodeObjectForKey:@"iden"];
self.name = [aDecoder decodeObjectForKey:@"name"];
self.address = [aDecoder decodeObjectForKey:@"address"];
}
return self;
}
- (void) encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.iden forKey:@"iden"];
[aCoder encodeObject:self.nome forKey:@"name"];
[aCoder encodeObject:self.indirizzo forKey:@"address"];
}
- (void) dealloc{
[super dealloc];
[name release];
[iden release];
[address release];
}
@end
它的工作正常,同时我有一个nsmutablearray,我插入这些名为“favorite”的对象 使用这个数组“最喜欢的”我填充tableview,并用NSUserDefault以这种方式保存它:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData* myClassArrayData = [NSKeyedArchiver archivedDataWithRootObject:appDelegate.favorite];
[defaults setObject:myClassArrayData forKey:@"favorite"];
当我第二次打开我的应用程序并显示我的tableview时,一切正常,但是当我尝试删除此tableview的一行时,我发生了崩溃...原因是类对象中的dealloc方法。
如果我评论这些方法:
//- (void) dealloc{
// [super dealloc];
// [name release];
// [iden release];
// [address release];
//}
我没有崩溃并且工作正常,这个案例的解决方案是什么?我应该评论dealloc方法吗?