5

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?

ICL1901
  • 7,632
  • 14
  • 90
  • 138

2 Answers2

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?

Community
  • 1
  • 1
Andrew Ebling
  • 10,175
  • 10
  • 58
  • 75
  • Good idea. Thanks. I'll try that now. – ICL1901 Aug 05 '15 at 11:01
  • I'm not sure how to implement this. The back function is actually being controlled by the main VC navigation controller. Should I simple override this with my own button? – ICL1901 Aug 05 '15 at 11:16
  • Please note, I have updated my question so it is more accurate. – ICL1901 Aug 05 '15 at 11:54
  • In that case I would check that you aren't accidentally triggering two backward navigations together. I believe I've seen this error when accidentally attempting that before. – Andrew Ebling Aug 05 '15 at 12:25
  • Thanks Andrew, I think that solved the issue. (I have to replicate this in 30+ controllers.).But I will mark it as solved. – ICL1901 Aug 06 '15 at 10:47
  • So, just to be clear, you're recommending disabling the UINavigationControllers back button and replacing it with your own as an unwind segue? I'm having a similar issue and checked that I'm not triggering two backward navigations together. – Matthew Knippen Sep 28 '15 at 05:11
  • If you are using a `UINavigationController` you do not need unwind segues, as the navigation controller handles this for you. I would recommend putting symbolic breakpoints on the `UINavigationController` pop methods and check whether something else is triggering a backwards navigation. Alternatively, temporarily set the `UINavigationControllers` delegate to monitor it's activity. – Andrew Ebling Sep 28 '15 at 08:58
  • 1
    @AndrewEbling -- could you please provide an example of this: "Alternatively, temporarily set the UINavigationControllers delegate to monitor it's activity. –" How do I do that? Thanks – ICL1901 Sep 29 '15 at 23:23
  • 1
    @DavidDelMonte have an object implement the `UINavigationControllerDelegate` protocol methods and log some messages to the console. Then create an instance of that object and assign it to your `UINavigationController`'s `delegate` property. Your implemented delegate methods should get called each time a transition is triggered. – Andrew Ebling Sep 30 '15 at 07:22
1

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).

Community
  • 1
  • 1
andrewbuilder
  • 3,629
  • 2
  • 24
  • 46