ios - 由于此错误 "Receiver (<ViewController: ) has no segue with identifier",Segue 将无法执行,但已识别出 segue

标签 ios objective-c iphone uiviewcontroller segue

我一整天都遇到同样的错误,我知道这是在说 Storyboard 中没有识别出 segue,但确实如此。以下是我认为相关的代码: 1.为 segue 发出信号的按钮的 IBAction。

-(IBAction)launchScanner:(id)sender{
    NSLog(@"launch Scanner pressed");
    [self performSegueWithIdentifier:@"launchScanner" sender:self];     
}
  1. 这是 prepare for segue 函数,我暂时将其留空,不确定是否需要在其中包含一些内容。

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([[segue identifier] isEqualToString:@"launchScanner"]){  
    
    }   
    }
    
  2. 我最初以编程方式制作所有内容,这是我实例化导航 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]; 
    
  3. 此外,这是我的 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/

相关文章:

ios - 如何让某些特定客户可以使用我的 iPhone 应用程序?

ios - 如何从 XCUIElementQuery UITesting 获取可见单元格计数

ios - Swift 中的自类分配等价物

iphone - 需要帮助使用自定义对象对 NSMutableArray 进行排序

ios objective-c , boolean 切换警告

iphone - 在 monotuch 中通过 CGBitmapContext 组合两个图像时如何避免质量损失

iphone - 响应式设计 - 网站在 iPhone 和较小的浏览器上显示不同

javascript - iOS Chrome 检测

ios - 无法在新的 iTunes Connect 中上传 GeoJSON 文件

ios - 为什么我的 UITextField 委托(delegate)方法没有被调用?