我有两个名为的应用程序,
这是我的ReceiveDataApp的StoryBoard
我可以将数据发送到接收应用程序,并可以通过以下方法进行处理,
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options;
但是,这里的问题是我想将我从SendDataApp接收的数据显示给我正在尝试使用以下方法来处理DetailViewController
的ReceivedDataApp,
Appdelegate.m
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController *viewController = (ViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"View"];
[viewController receivedURL:url];
return YES;
}
ViewController.m
- (void)receivedURL:(NSURL *)url {
[self performSegueWithIdentifier:@"detailIdentifier" sender:url];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"detailIdentifier"]) {
DetailViewController *detail = [segue destinationViewController];
detail.receivingURL = (NSURL *)sender;
}
}
但是,这给了我一些错误
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'detailIdentifier'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.
My two viewcontrollers embedded in UINavigationController
only. And, normally i can view detail page by button action. But, not by URL Scheme
What was the mistake here? And, am i doing anything wrong here?
Give me some suggestions or idea to handle this.
You instantiate your ViewController
in your AppDelegate's openURL
method and ARC immediately releases the view controller when that openURL
method returns. It doesn't survive long enough to be added to the navigation controller
您真正需要做的是获取当前显示的视图控制器(可能是您的“ View Controller
” ,也可能不是您的“ ”),然后执行此操作。
换句话说,在您的应用程序委托中:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
UIViewController *rootvc = self.window.rootViewController;
// make sure the root view controller is the ViewController class you want
if ([rootvc isKindOfClass: [ViewController class]])
{
ViewController * vc = (ViewController *)rootvc;
[vc receivedURL:url];
}
return YES;
}
您可以在此问题和此问题中看到更多我正在尝试使用答案做的事情。
最后,您确实必须重命名子类化的视图控制器,使其名称与超级通用的“视图控制器”和“详细信息视图控制器”名称不同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句