0
刪除數組對象我這樣一個genearl對象:IOS:與崩潰
.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我插入這些對象稱爲「最喜歡的」 隨着這個數組「最喜歡的」我填充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方法嗎?
+2 ABSolutely CoRREct ...,如果我可以:) –