简体   繁体   English

如何从XIB文件加载情节提要?

[英]How to load a storyboard from a XIB file?

I am trying to load a storyboard file from a XIB file when a button is clicked. 单击按钮时,我试图从XIB文件加载情节提要文件。 So in the IBAction method I have called the following line: 因此,在IBAction方法中,我调用了以下行:

- (IBAction)NextView:(id)sender
{
            UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    [mainStoryBoard instantiateViewControllerWithIdentifier:@"StoryViewController"];
}

But I get this error when I run the application Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x88672d0>) doesn't contain a view controller with identifier 'StoryViewController'' 但是Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x88672d0>) doesn't contain a view controller with identifier 'StoryViewController''运行应用程序Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x88672d0>) doesn't contain a view controller with identifier 'StoryViewController''时出现此错误Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x88672d0>) doesn't contain a view controller with identifier 'StoryViewController''

I check out other questions asked by people on stackverflow and found that generally this error is thrown when one forgets to put the identifier name of the View controller in the identity inspector for the view controller that one is trying to load. 我检查了人们在stackverflow上提出的其他问题,并发现,通常当人们忘记将View控制器的标识符名称放入要尝试加载的View控制器的身份检查器中时,就会引发此错误。 But I have done that too. 但是我也做到了。 In the storyboard the first viewController which is getting loaded is StoryViewController and I have set its identifier the same. 在情节提要中,要加载的第一个viewController是StoryViewController ,我将其标识符设置为相同。 Is there something else that I may be missing. 还有其他我可能会想念的东西吗? Please tell me how to correct it. 请告诉我如何纠正它。 在此处输入图片说明

You are setting the class name of the view controller only. 您仅设置视图控制器的类名。 I can see that the storyboard ID filed as empty. 我可以看到情节提要ID存档为空。 Set the Storyboard ID to StoryViewController in the Identity section 在“ 身份”部分中将情节提要ID设置为StoryViewController

在此处输入图片说明

- (IBAction)NextView:(id)sender
{
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    StoryViewController *storyViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"StoryViewController"]; 
    [self presentViewController:storyViewController animated:YES completion:nil]; //  present it  
     //[self.navigationController pushViewController:storyViewController animated:YES];// or push it

 }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM