65.9K
CodeProject 正在变化。 阅读更多。
Home

避免 NSFetchedResultsController 导致应用崩溃

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (1投票)

2012年1月5日

CPOL
viewsIcon

14247

如何阻止应用因为“-[MyClass controllerWillChangeContent:]: message sent to deallocated instance”而崩溃?

我的应用为什么会因为“-[MyClass controllerWillChangeContent:]: message sent to deallocated instance”而崩溃?被接受的答案是将 NSFetchedResultsController 设置为 nil 当视图消失时。
-(void)viewWillDisappear:(BOOL)animated {
	self.fetchedResultsController = nil;
}
对我来说,这样做虽然解决了一个问题,却带来了十二个新的问题,例如列表无法显示、删除对象等等。所以我回滚了代码并仔细检查。真正的问题发生在 弹出 UITableViewController 的时候。因此,借鉴了将 NSFetchedResultsController 设置为 nil 可能有所帮助的想法,我在弹出视图之前将 NSFetchedResultsController 设置为 nil,一切都恢复了正常。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	...
	self.fetchedResultsController = nil; //This is the line that fixed issue
	[self.navigationController popViewControllerAnimated:YES];
}
希望这个技巧能帮到你。Rob
© . All rights reserved.