简体   繁体   English

从AppDelegate调用之后,performSegueWithIdentifier NSInvalidArgumentException

[英]performSegueWithIdentifier NSInvalidArgumentException after call from AppDelegate

Hey together, 嘿,在一起

I am calling a void with some parameters from the AppDelegate on my main view. 我在主视图上使用AppDelegate的一些参数调用了void。 This is done if a push notification is received: 如果收到推送通知,则完成此操作:

MainViewController *mainView = [[MainViewController alloc] init];
[mainView showPushView:pushDataObject];

The called void @ the MainView doing some data operating stuff and after that it should load the pushView: 称为void @ MainView做一些数据操作的东西,然后它应该加载pushView:

- (void)showPushView: (PFObject *)pushDataObject {
    NSLog(@"Push Data object transfered %@", pushDataObject);
    pushItem = pushDataObject;
    //All working fine to this point 
    [self performSegueWithIdentifier:@"showPushObject" sender:self];
}

Now the problem is that the app is crashing at [self performSegueWithIdentifier:@"showPushObject" sender:self]; 现在的问题是应用程序在[self performSegueWithIdentifier:@"showPushObject" sender:self];崩溃[self performSegueWithIdentifier:@"showPushObject" sender:self]; with this Error: 出现此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'Receiver (<MainViewController: 0x145b80e0>) has no segue with identifier 'showPushObject''
*** First throw call stack:
(0x2e51fe83 0x3887c6c7 0x30f656d9 0xbeb11 0xb2a23 0x1745f7 0x38d610c3 0x38d610af 0x38d639a9 0x2e4ea5b1 0x2e4e8e7d 0x2e453471 0x2e453253 0x3318d2eb 0x30d08845 0xafecd 0x38d75ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

I think that there is a problem because I call the void from the AppDelegate, am I right? 我认为这是有问题的,因为我从AppDelegate调用了void,对吗?

Those anyone know a fix for that problem? 那些人知道解决该问题的方法吗?

Thanks a lot! 非常感谢! Best regards from Germany :) 来自德国的问候:)

PS If I call [self performSegueWithIdentifier:@"showPushObject" sender:self]; PS如果我调用[self performSegueWithIdentifier:@"showPushObject" sender:self]; with a button or something on the MainViewController all working fine... :/ 用按钮或MainViewController上的任何东西都可以正常工作...:/

Your problem is this line: 您的问题是这一行:

MainViewController *mainView = [[MainViewController alloc] init];

because it means that the mainView instance doesn't have a storyboard (so it can't have any segues). 因为这意味着mainView实例没有情节mainView (因此它不能包含任何脚本)。

When you run it from a button the controller instance must have been created from a storyboard. 从按钮运行时,必须已从情节提要中创建了控制器实例。

So, to fix, load the storyboard and instantiate mainView from it. 因此,要修复,加载情节mainView从中实例化mainView Then the segue will work. 然后segue将起作用。


UIStoryboard *storyboard4Inch = [UIStoryboard storyboardWithName:@"Storyboard4Inch" bundle:nil];
UIViewController *mainViewController = [storyboard4Inch instantiateViewControllerWithIdentifier:@"MainViewController"];
[mainViewController showPushView:pushDataObject];

In order for the segue to work, you need to have the storyboard loaded in the mainView when you start it that way. 为了使segue正常工作,以这种方式启动故事板时,需要将其放置在mainView中。 Try instead something like this: 尝试这样的事情:

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:@"kYourMainViewControllerIdentifier"];
self.window.rootViewController = firstViewController;
[self.window makeKeyAndVisible];

Remember to give an identifier to your root view controller and change it in this piece of code. 记住要给根视图控制器一个标识符,并在这段代码中对其进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从didFinishPickingMediaWithInfo调用performSegueWithIdentifier - Call performSegueWithIdentifier from didFinishPickingMediaWithInfo performSegueWithIdentifier给了我NSInvalidArgumentException - performSegueWithIdentifier gives me NSInvalidArgumentException 从AppDelegate更新WebView时出现NSInvalidArgumentException - NSInvalidArgumentException when updating WebView from AppDelegate 从AppDelegate发送本地通知时出现NSInvalidArgumentException - NSInvalidArgumentException when sending local notification from AppDelegate 在appDelegate上通过swift接收远程通知后,关闭视图并推送(或performSegueWithIdentifier)? - DismissView and push (or performSegueWithIdentifier) after Receive Remote Notification on appDelegate by swift? 如何从XIB调用performSegueWithIdentifier? - How to call performSegueWithIdentifier from xib? 无法从UITableViewCell调用performSegueWithIdentifier - Cannot call performSegueWithIdentifier from a UITableViewCell 可以将performSegueWithIdentifier与AppDelegate一起使用吗? - Can performSegueWithIdentifier be used with the AppDelegate? 执行函数以从另一个类调用performSegueWithIdentifier - Execute function to call performSegueWithIdentifier from another class 是否可以从另一个类调用performSegueWithIdentifier? - Is it possible to call a performSegueWithIdentifier from another class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM