我一整天都遇到同样的错误,我知道这是在说 Storyboard 中没有识别出 segue,但确实如此。以下是我认为相关的代码: 1.为 segue 发出信号的按钮的 IBAction。
-(IBAction)launchScanner:(id)sender{
NSLog(@"launch Scanner pressed");
[self performSegueWithIdentifier:@"launchScanner" sender:self];
}
这是 prepare for segue 函数,我暂时将其留空,不确定是否需要在其中包含一些内容。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([[segue identifier] isEqualToString:@"launchScanner"]){ } }
我最初以编程方式制作所有内容,这是我实例化导航 Controller 的方式(在 appdelegate.m 中):
ViewController *myViewController = [[ViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController]; _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window.rootViewController = navigationController; [_window makeKeyAndVisible];
- 此外,这是我的 Storyboard设置的图片和证明已识别 segue 的证据 Image 1 Image 2
最佳答案
如果您想以编程方式实例化您的导航 Controller ,您需要从 Storyboard 中获取对它的引用。如果您需要在加载初始 VC 之前在应用程序委托(delegate)中执行某些功能,则可以使用它。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UINavigationController *initialNavVc = (UINavigationController *)[mainStoryboard instantiateInitialViewController];
self.window.rootViewController = initialNavVc;
关于ios - 由于此错误 "Receiver (<ViewController: ) has no segue with identifier",Segue 将无法执行,但已识别出 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33470091/