I have Core Spotlight set up in my app. I navigate to a specific view controller within a navigation controller that displays a webview webpage based on the title. So for example:
我在app中设置了核心聚光灯。我在导航控制器中导航到一个特定的视图控制器,该控制器根据标题显示一个webview页面。举个例子:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {
if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) {
// This activity represents an item indexed using Core Spotlight, so restore the context related to the unique identifier.
// The unique identifier of the Core Spotlight item is set in the activity’s userInfo for the key CSSearchableItemActivityIdentifier.
NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
NSString *valueForUID = [self valueForKey:uniqueIdentifier];
self.tabBar = (UITabBarController *)self.window.rootViewController;
self.tabBar.selectedIndex = 0;
UINavigationController *selectedNav=(UINavigationController *)self.tabBar.selectedViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
WebViewController *webVCVC = [storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
webVC.title = uniqueIdentifier;
webVC.titleDetail = valueForUID;
[selectedNav presentViewController:webVC animated:YES completion:nil];
}
}
In short, the webVC loads a specific web page based on it's self.title and titleDetail, these values change because every spotlight unique ID is different.
简而言之,webVC基于它自己加载一个特定的web页面。标题和titleDetail,这些值会改变,因为每个spotlight惟一ID都是不同的。
The issue isn't if the first spotlight index is selected, everything works fine. however, if I select the new 'Back To %@' button and go back to Spotlight to select a new search item, I get the following error:
问题不是如果选择了第一个焦点指数,一切都很好。但是,如果我选择新的“返回到%@”按钮并返回Spotlight以选择新的搜索项,我将得到以下错误:
Warning: Attempt to present <WebViewController: 0x7fced37c8be0> on <UINavigationController: 0x7fced403fa00> whose view is not in the window hierarchy!
So I thought all I had to do was dismiss 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 doesn't work either, I get the following warning/error:
这也不起作用,我得到以下警告/错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
Which makes sense. How do i circumvent this in this particular instance?
这是有意义的。在这个特定的例子中,我如何规避这个问题?
2 个解决方案
#1
0
A UINavigationController
, even though it inherits from UIViewController
, doesn't have a non-nil
view
of its own, so you can't call presentViewController:animated:completion:
on top of it. I think that you're confusing presentViewController
(which displays a modal, and needs to be sent to the view controller that's currently being displayed) with pushViewController:animated:
, which is sent to the current view controller's navigationController
.
UINavigationController,即使它从UIViewController继承,也没有它自己的非nil视图,所以你不能调用presentViewController:animated:completion: on top of it。我认为你混淆了presentViewController(显示一个模态,需要发送给当前显示的视图控制器)和pushViewController:animated:,它被发送给当前视图控制器的navigationController。
#2
0
I fixed it by dismissing it from the navigation controller:
我把它从导航控制器中删除了:
//Instead of this
[webVC dismissViewControllerAnimated...
//I used this
[selectedNav.presentedViewController dismissViewControllerAnimated...
#1
0
A UINavigationController
, even though it inherits from UIViewController
, doesn't have a non-nil
view
of its own, so you can't call presentViewController:animated:completion:
on top of it. I think that you're confusing presentViewController
(which displays a modal, and needs to be sent to the view controller that's currently being displayed) with pushViewController:animated:
, which is sent to the current view controller's navigationController
.
UINavigationController,即使它从UIViewController继承,也没有它自己的非nil视图,所以你不能调用presentViewController:animated:completion: on top of it。我认为你混淆了presentViewController(显示一个模态,需要发送给当前显示的视图控制器)和pushViewController:animated:,它被发送给当前视图控制器的navigationController。
#2
0
I fixed it by dismissing it from the navigation controller:
我把它从导航控制器中删除了:
//Instead of this
[webVC dismissViewControllerAnimated...
//I used this
[selectedNav.presentedViewController dismissViewControllerAnimated...