【发布时间】:2012-03-23 15:20:12
【问题描述】:
此项目适用于装有 iOS 5 且使用 ARC 和 Core Data 的 iPhone。
全部内置 Xcode Storyboard,我有一个带有几个标签的 UITabBarController。其中三个视图是UITableViewControllers,附有UISearchDisplayController。如果我在 iPhone 模拟器中模拟内存警告,则任何未激活的视图都会被转储,当我使用 searchDisplayController 点击其中一个视图的选项卡时,NSZombieEnabled 会告诉我-[UISearchDisplayController retain]: message sent to deallocated instance。
这是我的-didReceiveMemoryWarning:
- (void)didReceiveMemoryWarning
{
[(PahAppDelegate *)[[UIApplication sharedApplication] delegate] saveContext];
// Release any cached data, images, etc that aren't in use.
self.searchWasActive = [self.searchDisplayController isActive];
self.savedSearchTerm = [self.searchDisplayController.searchBar text];
self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
self.fetchedResultsController.delegate = nil;
self.fetchedResultsController = nil;
self.searchFetchedResultsController.delegate = nil;
self.searchFetchedResultsController = nil;
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
我最好的猜测是UITableViewController 也转储了子视图,无论出于何种原因,当我返回其他选项卡时,它都不会重新创建它们。由于所有这些功能都内置在 Storyboard 中,我不太确定如何请求它重新加载有问题的 searchDisplayController。
注意:我从未见过该应用在现实世界中的设备上执行此操作 (我的 beta 测试人员也没有),但我不希望 Apple 拒绝 因此批准该应用程序;加上修复它似乎 做正确的事。
searchDisplayController 是一个只读属性,所以我不知道要采取什么策略才能将内容加载到应有的状态。
【问题讨论】:
-
似乎它可能是情节提要中的错误。现在通过在代码中创建
UISearchDisplayController来解决,正如 Brian Cooke 在下面建议的那样。
标签: ios memory-management uitableview uisearchdisplaycontroller uistoryboard