我想在电子邮件中发送一个链接来启动特定的UIViewController(它实际上是一个UITableViewController)。我可以使用CustomURL方案从链接打开我的应用程序,我已经编写了URLHandler方法(最新的方法而不是已弃用的方法),我可以解析URL,但我无法打开页面。我正在使用故事板,以及UINavigatorController和UITabBarController。我要打开的场景的StoryboardID是“ApprovalView”。
当我运行以下代码时,出现以下错误:
UIViewControllerHierarchyInconsistency',原因:'视图一次只能与一个视图控制器关联!查看; layer =; contentOffset:{0,0}>与....关联
我现在正在应用程序中运行它。如果我实际点击URL链接,应用程序就会挂起。
我查看了有关此错误的其他StackOverflow帖子,这似乎意味着我已经将视图连接到两个viewControllers。我认为那是因为这条线
ApprovalViewController * appViewController = [storyboard instantiateViewControllerWithIdentifier:@“ApprovalView”];
然而,建议的解决方案似乎不起作用,我相信因为我使用的是右舷。我可以打电话给我的segue吗?
非常感谢任何帮助!
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Get the host and query
// the host is what expense to go to and the query is the noteID
NSString *tmpHost = [[NSString alloc] init];
tmpHost = [[url host] substringFromIndex:1];
NSString *tmpQuery = [[NSString alloc] init];
tmpQuery = [url query];
// Go to a page
// UIViewController *expenditureView =
// [storyboard instantiateViewControllerWithIdentifier:@"ApprovalView"];
// UINavigationController *navVC = [[UINavigationController alloc]
// initWithRootViewController:expenditureView];
// UIViewController *expenditureController =
// [self.window.rootViewController.storyboard
// instantiateViewControllerWithIdentifier:@"ApprovalView"];
// UINavigationController *navVC =
// [self.window.rootViewController.storyboard
// instantiateViewControllerWithIdentifier:@"navigationController"];
// UIViewController *currentVC = self.window.rootViewController;
// _window.rootViewController = navVC;
// [currentVC presentViewController:navVC animated:NO completion:nil];
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
ApprovalViewController *appViewController =
[storyboard instantiateViewControllerWithIdentifier:@"ApprovalView"];
UINavigationController *navController = [appViewController.storyboard
instantiateViewControllerWithIdentifier:@"navigationController"];
navController.view = appViewController.view;
_window.rootViewController = navController;
UIViewController *currentVC = self.window.rootViewController;
[currentVC presentViewController:navController animated:NO completion:nil];
// [self.window addSubview:self.navVC.view];
// [self.window setRootViewController:self.navVC];
// Navigation
// UINavigationController *navCon = [[UINavigationController alloc] init];
//[navVC pushViewController:expenditureView animated:NO];
//[expenditureView.navigationController setNavigationBarHidden:FALSE
// animated:YES];
// self.window.rootViewController = expenditureView;
return YES;
}