Why: “Attempting to load .. while deallocating… :UISearchController:”

假装没事ソ 提交于 2019-12-22 06:58:36

问题


I have root storyboard that has a button that pushes ViewControllerB.

ViewControllerB has a sort controller UISortController.

ViewControllerB has a "back" method that is controlled by the root nav controller.

I'm getting the following warning:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController: 0x7ff10258ba60>)

I used Apple's sample (membership required) to add the new UISearchController.

Has anyone come across this? How do I resolve it?


回答1:


I would recommend using Storyboard Unwind Segues instead: https://developer.apple.com/library/ios/technotes/tn2298/_index.html

This insightful post also has a wealth of very useful implementation detail:

What are Unwind segues for and how do you use them?




回答2:


I've come across the same console error message, but note the following regarding my Xcode project:

  • segues to navigation controllers must remain due to their use with a split view controller (to the detail view controller);
  • (and according to @AndrewEbling comments above) the code does not require unwind segues as the navigation controller manages (a proportion of) the tasks automatically;
  • also the code does not require unwind segues as blocks are used to set properties in parent view controller.

Thanks to comments by Leehro and Clafou in this SO answer the console error message was suppressed by using following line of code in viewDidLoad (note that there is no need to insert this in dealloc):

[self.searchController loadViewIfNeeded]; (note available from iOS 9).



来源:https://stackoverflow.com/questions/31830302/why-attempting-to-load-while-deallocating-uisearchcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!