我有一个带有动作(toggleApplication)的按钮,可以打开另一个应用程序。当我从打开的应用程序返回到我的应用程序时,我想要转到另一个视图。但是我的代码中出现以下错误:
Receiver(RootViewController:0x1f192450)没有带标识符'showReceipt'的segue
AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
RootViewController *controller = [RootViewController alloc];
return [controller handleURL:url];
}
RootViewController.m
- (IBAction)toggleApplication:(id)sender{
// Open application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];
}
- (BOOL)handleURL:(NSURL *)url{
[self performSegueWithIdentifier:@"showReceipt" sender:self];
return YES;
}
答案 0 :(得分:3)
使用NSNotificationCenter计算出来。
<强> AppDelegate.m 强>
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"segueListener" object:nil];
return YES;
}
<强> RootViewController.m 强>
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptSegue) name:@"segueListener" object:nil];
}
- (IBAction)toggleApplication:(id)sender{
// Open application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];
}
- (void)receiptSegue{
[self performSegueWithIdentifier:@"showReceipt" sender:self];
}
完全符合我的要求。不知道这是不是正确的做法。