当我尝试发布字典时,我得到一个例外.
这是我的代码:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (!tableDataDictionary) { DebugLog(@"initializing tableDataDictionary"); tableDataDictionary = [ [NSMutableDictionary alloc] init]; } } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO]; [tableDataDictionary release]; }
我该如何解决?
您很可能需要取消tableDataDictionary实例变量.否则,第一次运行这些方法时,它将正常工作,但第二次,tableDataDictionary将不会为nil,并将指向dealloc'd指针; 因此不会进行alloc调用,并且当调用viewWillDisappear:时,它将尝试再次释放该指针.所以,解决它:
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO];
[tableDataDictionary release]; tableDataDictionary = nil;
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO];
[tableDataDictionary release]; tableDataDictionary = nil;
}