Application tried to present a nil modal view controller on target “Current View Controller”解决方案
情景再现
1,自定义一个storyboard:
打开xcode,按下cmd+N,新建一个Storyboard--->next

将新建立的storyboard命名为:TestViewController--->create

在TestViewController.storyboard上加上一个label,其text为:Hello-ios
2,编写UIButton的UIControlEventTouchUpinside事件:
- (IBAction)btnClick:(id)sender {
//创建加载storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"TestViewController" bundle:nil];
//将控制器关联到storyboard
_viewOfStoryboard = [storyboard instantiateInitialViewController];
_viewOfStoryboard.view.backgroundColor = [UIColor whiteColor];
[self dismissViewControllerAnimated:YES completion:nil];
[self presentViewController:_viewOfStoryboard animated:YES completion:nil];
}
运行操作如下:

在加载自定义storyboard界面遇到如下问题

错误原因:应用程序视图向目标展示一个空模式形态的视图控制器,简单的说,storyboard中的视图控制器是空的。
3,解决方案:
- 在StackOverflow上给了相关回答(下面是个人的翻译,如有误请指出)
Check the identifier of the viewcontroller, if it is the same that you mentioned in storyboard。
- 检查viewcontroller上的标识符,确保它在storyboard上是独一无二的。
Make sure that your buddiesOrFacebook 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。
- 确保你的buddies或者facebook(这句话没有理解)不是空的。可以设置断点进行调试,如果该对象是空的,那么就是storyboard的连接出现了问题。
If your current viewcontroller is not launched from storyboard then get storyboard object like this :
如果当前的viewcontroller没有开始加载,可以参考下面的标准写法:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController * buddiesOrFacebook = [storyboard instantiateViewControllerWithIdentifier:@"BuddiesFBFriends"] ;
[self presentViewController:buddiesOrFacebook animated:YES completion:nil];
上面的解决方案并没有解决我的问题,于是采取了第二套解决方案。
打开TestViewController.storyboard视图,操作如下:

选中Is Initial View Controller,确保viewcontroller被初始化。
4,结果:
最后运行正确,如下图:

Application tried to present a nil modal view controller on target “Current View Controller”解决方案的更多相关文章
- Android中View绘制优化之三---- 优化View
本文原创, 转载请注明出处:http://blog.csdn.net/qinjuning 译三: 优化视图 关于如何设计自定义View以及响应触摸时间等,请看Android developer : 地 ...
- 键盘弹出后上提view隐藏后下拉view还原并修改scroll过程中旋转屏幕到竖屏view显示错误
1,注册键盘相应事件 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillSho ...
- Asp.Net MVC中Controller、Action、View是如何激活调用的
上篇我们介绍了MVC的路由,知道在注册路由的时候会创建一个MvcHandler将其和Url规则一起放入到了RouteCollection中,之后请求通过UrlRoutingModule,根据当前的UR ...
- ui5 call view or method from another view
// call view or method from another view //# view call // var view2=sap.ui.jsview("ui5d.popup01 ...
- View (五)自定义View的实现方法
一些接触Android不久的朋友对自定义View都有一丝畏惧感,总感觉这是一个比较高级的技术,但其实自定义View并不复杂,有时候只需要简单几行代码就可以完成了. 如果说要按类型来划分的话,自定义Vi ...
- 在Android中将子View的坐标转换为父View的坐标
在Android中,我们有时候可能会将子View的坐标转换为父View中的坐标.感觉很有用,分享给大家. 在Launcher中有这么一段代码可以完成这项工作. public float getDes ...
- 【转】Android绘制View的过程研究——计算View的大小
Android绘制View的过程研究——计算View的大小 转自:http://liujianqiao398.blog.163.com/blog/static/18182725720121023218 ...
- IOS 7 Study - Manipulating a Navigation Controller’s Array of View
ProblemYou would like to directly manipulate the array of view controllers associated with aspecific ...
- ASP.NET MVC 学习2、从Controller传递数据到View
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-view 一,Control ...
随机推荐
- tar.gz file installation
1. tar xzvf filename.tar.gz 2. cd filename 3. ./configure ./configure --prefix="path" 4. ...
- linux安装eclipse
1 采用ssh无法运行eclipse, 错误如下: Autolaunch error: X11 initialization failed.\n, 打开日志文件: org.eclipse.swt. ...
- angularjs 迭代器
angularjs 迭代器可以使用管道字符(|)添加到表达式和指令中. 有以下五种转换数据的迭代器: (1)currency-格式化数字为货币格式. (2)filter-从数组中选择一个一个子集. ( ...
- 转: MySQL 赋予用户权限(grant %-远程和localhost-本地区别)
相关参考资料: MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. gr ...
- 安装配置sock5代理
环境准备及安装 yum -y install pam-devel openldap-devel cyrus-sasl-devel yum -y install openssl-devel.x86_64 ...
- 关于清除丢失贴图与IES文件
fn YY_clrmessingmaps = ( YY_messingmap = #() allBitmaps = getClassInstances BitmapTexture -- 所有材质 to ...
- 解决MVC中使用BundleConfig.RegisterBundles引用Css及js文件发布后丢失的问题
ASP.NET MVC4,ASP.NET MVC5中对JS和CSS的引用又做了一次变化,在MVC3中我们这样引用资源文件: <link href="@Url.Content(" ...
- 【转】Reactor与Proactor两种模式区别
转自:http://www.cnblogs.com/cbscan/articles/2107494.html 两种IO多路复用方案:Reactor and Proactor 一般情况下,I/O 复用机 ...
- 解决TalbleView头部或底部子控件不显示问题
在自定义cell头部控件UITableViewHeaderFooterView(和自定义cell的方法几乎一样)时,出现了头部控件子控件不显示的问题. 注意和自定义cell的区别. .h文件 #imp ...
- Mysql 自定义HASH索引带来的巨大性能提升----[真相篇]
推倒重来 俗话说no zuo no die why you try,这时候我又忍不住zuo了,吭哧吭哧的把解决过程发上博客,向全世界宣布,哥又搞定个难题. 剧情的发展往往是看起来主角完全掌握了局势的情 ...