【问题标题】:How can I re-load a searchDisplayController built in Storyboard, after a memory warning?在出现内存警告后,如何重新加载 Storyboard 中内置的 uisearchDisplayController?
【发布时间】: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


【解决方案1】:

这绝对看起来像是一个可能是故事板的错误。正如这里提到的:UISearchDisplayController causes crash after viewDidUnload,一个使用 Storyboards 和 UISearchDisplayController 的全新项目甚至可以在不将 UISearchDisplayController 的插座连接到您的控制器的情况下重现这一点。该线程中的建议似乎很理智,在代码中创建 UISearchDisplayController 。我无法保证解决方法,因为我没有对其进行测试,但我很好奇并且确实重现了新项目 = 崩溃声明并看到了完全相同的东西。

【讨论】:

  • 我得出了同样的结论。我自己构建了一个示例测试项目,只是在 Storyboard 中进行了布局,没有添加任何自定义代码,它仍然可以重现。
  • 我将我的答案添加到 Brain 提到的另一个线程中。请看stackoverflow.com/questions/8567525/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-28
  • 2015-12-24
  • 2012-03-18
  • 1970-01-01
  • 2012-04-02
  • 2010-11-24
相关资源
最近更新 更多