用代码调用Storyboard里面的viewController
今天在帮助群里的一个朋友弄pop事件,在他那边,当前的viewcontroller,不能pop出去。
初步估计,他的ViewController层级多,他自己没有理清。
因为pushViewController的时候,是执行栈入的原则,先进后出,后进先出。
比如A->B->C->D,他这个时候,想popB,但是B的上面还有两个,分别为C和D,C和D没有出来,这个时候,B就没有办法出来。所以,即使执行了pop语句,也达不到pop的效果。
然后中午我自己用storyboard拖了几个东西,简单实现了这个效果,发现自己对storyboard还是不太熟,要仔细实践啊!
- 调出storyboard方法:
UIStoryboard * mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
Parameters
|
name |
The name of the storyboard resource file without the filename extension. This method raises an exception if this parameter is nil. |
|
storyboardBundleOrNil |
The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application. |
Return Value
A storyboard object for the specified file. If no storyboard resource file matching name exists, an exception is thrown with description: Could not find a storyboard named 'XXXXXX' in bundle....
Discussion
Use this method to retrieve the storyboard object containing the view controller graph you want to access. All of the resources associated with the storyboard must be in the bundle indicated by the storyboardBundleOrNil parameter.
- Name则是自己起的,在.storyboard前面的名字,如果不动,则默认是Main,而且不需要添加文件的扩展名,如果加了,就会报错;
- bundle:这个参数包含storyboard的文件以及和它相关的资源,如果为空,则会调用当前程序的main bundle
这样,就能拿到程序里面的storyboard了。
2.调出里面的viewcontroller
我是在里面直接拖拽了几个viewcontroller,当需要加载这几个viewcontroller的时候,有3件事情要做
2.1 新建ViewController的.h和.m文件,并且将storyboard里面的nib文件的class,也指向对应的VC;
2.2 设置Storyboard ID,在Custom Class下面,有一个Identity,这个设置标识符,我们就可以找到它了,像Cell的标识符,一般和头文件名称设置为一样就可以。
2.3 在代码里面调用它:
UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
DViewController * dVC = [mainStoryBoard instantiateViewControllerWithIdentifier:@"DViewController"];
[self.navigationController pushViewController:dVC animated:YES];
这样就可以了。功能就基本实现了。
熟能生巧--欢迎大家加入我们的交流群:461093715
用代码调用Storyboard里面的viewController的更多相关文章
- Android原生调用mui里面的js如何实现
遍历所有运行中的webview页面,采用自带的SDK方法进行获取所有的IWebview.MUI中自带的webview是一个IWebviewArrayList<IWebview> webli ...
- idea安装testng插件后,无法使用调用testng里面的类
1.已经安装好idea的testng插件,并且应用上相关的两个插件. 2.已经导入maven仓库的testng.jar,并且重启过idea后:发现不能调用. 本人在百度很多相关资料,始终没有找到解决方 ...
- ArcEngine 调用GP里面的Merge工具
这两天,为ArcEngine中的Merge工具的调试伤头脑筋,明明很简单的事情,就是搞不掂儿.今天忽然想到是否是中文的关系,果然,把中文修改成英文成功了.真是快郁闷死了! public static ...
- 自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个
自己改写了一个图片局部放大的jquery插件页面里面的html代码少了,同一个页面可以调用多个,兼容ie8以上浏览器,别忘了引用jquery,我用的jquery/1.11.0/其他版本没有测试,另外需 ...
- 我也谈谈 代码调用存储过程超时,SQL Server Management Studio里运行很快的问题
最近遇到了一个问题就是 一个执行速度很快的存储过程,在代码中调用的时候却超时了. 后来看到了两篇文章: 其中一篇是这样介绍的 今天同事用代码调用存储过程时超时,在SQL Server Manageme ...
- [Android] (在ScrollView里嵌套view)重叠view里面的onTouchEvent的调用方法
在我前面的自定义裁剪窗口的代码中,我把裁剪的view放在了大的scrollview里,这样就出现了程序只能触发scrollview,无法操作我的裁剪窗口.所以我加了那篇博客下面最后两段代码.其实我遇到 ...
- c#调用js,以及js调用C#里的函数, c#自己生成js代码,实现对web的控制
using mshtml;using System;using System.Collections.Generic;using System.Linq;using System.Security.P ...
- jQuery file upload里面的_create的调用和_initEventHandlers的调用
首先是jquery.ui.widget.js中_createWidget方法内部调用 this._create(); this._trigger( "create", null, ...
- dede文章调用时过滤调 body里面的style属性和值
dede 发布文章的时候会在里面的标签中添加一些style 属性,现在改网站想去掉这些属性和里面的值,因为文章太多所以就用下面的方法 \include\arc.listview.class.php 在 ...
随机推荐
- 【wikioi】1022 覆盖(匈牙利)
http://www.wikioi.com/problem/1022/ 好不容易来一次1A,,水题啊.. 染色后裸匈牙利orz #include <cstdio> #include < ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树套树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 这题调了我相当长的时间,1wa1a,我是第一次写树套树,这个是树状数组套splay,在每个区间 ...
- [转]OBOUT ASP.NET HTML Editor - Insert HTML
本文转自:http://www.obout.com/editor_new/sample_InsertHTML.aspx Example demonstrates how to access HTML ...
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- ScrollFix.js:一个 iOS5 溢出滚动的(有限)修复方案
Update: Unfortunately this does not 100% solve the problem, the script falls down when handling touc ...
- AngularJS 初识笔记
test.html: <!DOCTYPE html> <html lang="en" ng-app> <head> <meta chars ...
- pdfkit安装使用
centos 安装pdfkit1.先安装pdfkit依赖包 wkhtmltopdf 安装方式: # wget http://download.gna.org/wkhtmltopdf/0.12/0.12 ...
- Windows下的Objective-C集成开发环境(IDE)
Windows下的Objective-C集成开发环境(IDE) 分类: Objective-C2012-04-20 21:54 26631人阅读 评论(42) 收藏 举报 windowside编译器c ...
- PHP CURL 多线程 GET/POST 类
PHP CURL 多线程 GET/POST 类 2015-01-01 分类:技术文章 阅读(623) 评论(0) 如果有需要更正或更高效的建议,欢迎在OSchina分享~\(≧▽≦)/~ http:/ ...
- MySql练习+加源代码
一.设有一个数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1 ...