I have a Core Spotlight configured in my application. I move on to a specific view controller in a navigation controller that displays a webview webpage based on the title. For example:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler { if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) {
In short, webVC loads a specific web page based on its self.title and titleDetail, these values ββchange because each unique spotlight identifier is different.
The problem is not that the first searchlight index is selected, everything works fine. however , if I select the new "Back to% @" button and return to Spotlight to select a new search item, I get the following error:
Warning: Attempt to present <WebViewController: 0x7fced37c8be0> on <UINavigationController: 0x7fced403fa00> whose view is not in the window hierarchy!
So, I thought that all I had to do was discard the current view every time and reload it:
self.tabBar = (UITabBarController *)self.window.rootViewController; self.tabBar.selectedIndex = 0; UINavigationController *selectedNav=(UINavigationController *)self.tabBar.selectedViewController; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; WebViewController *webVC = [storyboard instantiateViewControllerWithIdentifier:@"WebViewController"]; [webVC dismissViewControllerAnimated:NO completion:^{ webVC.title = pubNum; webVC.titleString = pubTitle; [selectedNav presentViewController:webVC animated:YES completion:nil]; }];
This does not work either, the following warning / error appears:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
It makes sense. How to get around this in this particular case?
source share