使用iOS的Storyboard ID以编程方式调用视图控制器 [英] Call a view controller programatically using storyboard id iOS

查看:125
本文介绍了使用iOS的Storyboard ID以编程方式调用视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • MainViewController中,我以编程方式从xib中打开一个视图.这 xib视图包含UIButton. xib成功打开.
  • 点击该UIButton我要移动FeedBackViewController
  • In MainViewController I open a view from a xib programmatically. This xib view contains a UIButton. The xib opens successfully.
  • On click of that UIButton I want to move FeedBackViewController
  • 这是我单击UIButton

FeedBackViewController *view=[self.storyboad instantiateViewControllerWithIdentifier:@"FeedBackView"];
[self presentViewController:view animated:YES completion:nil];

但是它崩溃了,我收到以下消息:

But it is crashing and I am receiving the following message:

由于未捕获的异常"NSInvalidARgumentException"而终止应用程序,原因:应用程序试图在目标FutureOrderViewController上显示nil模态视图控制器:0x199a4a30.

Terminating app due to uncaught exception 'NSInvalidARgumentException', reason: 'Application tried to present a nil modal view controller on target FutureOrderViewController: 0x199a4a30.

推荐答案

检查这些内容

检查视图控制器的标识符(如果与情节提要中提到的标识符相同)

Check the identifier of the viewcontroller, if it is the same that you mentioned in storyboard

确保您的视图对象不是nil.在该行和底部的调试区域上设置一个断点,以查看对象是否不是nil.如果为零,则问题在于情节提要板连接

Make sure that your view object is not nil. Set a breakpoint on that line and on the debug area at the bottom see whether the object is not nil. If it is nil then problem lies in the storyboard connection

如果当前的ViewController不是从情节提要中启动的,则获取情节提要对象,如下所示:

If your current viewcontroller is not launched from storyboard then get storyboard object like this :

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * feedbackVC = [storyboard   instantiateViewControllerWithIdentifier:@"FeedBackView"] ;
[self presentViewController:feedbackVC animated:YES completion:nil];

这篇关于使用iOS的Storyboard ID以编程方式调用视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆