[英]Segue won't perform due to this error “Receiver (<ViewController: ) has no segue with identifier” but segue is identified
我整天都遇到了同样的错误,我知道这是在故事板上没有识别出segue,而是这样。 以下是我认为相关的代码:1.IBAction表示正在发出信号的按钮。
-(IBAction)launchScanner:(id)sender{
NSLog(@"launch Scanner pressed");
[self performSegueWithIdentifier:@"launchScanner" sender:self];
}
这是segue功能的准备工作,我暂时将其留空,不确定是否需要在其中包含某些内容。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([[segue identifier] isEqualToString:@"launchScanner"]){ } }
我最初以编程方式进行了所有操作,这是我实例化导航控制器的方式(这在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];
如果要以编程方式实例化导航控制器,则需要从情节提要中获取对其的引用。 如果需要在加载初始VC之前在应用程序委托中执行某些功能,则可以使用此功能。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UINavigationController *initialNavVc = (UINavigationController *)[mainStoryboard instantiateInitialViewController];
self.window.rootViewController = initialNavVc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.