Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2621132
  • 博文数量: 877
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5921
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 12:25
个人简介

技术的乐趣在于分享,欢迎多多交流,多多沟通。

文章分类

全部博文(877)

文章存档

2021年(2)

2016年(20)

2015年(471)

2014年(358)

2013年(26)

分类: iOS平台

2015-08-20 12:52:22

获取Storyboard中单独的控制器
http://www.cnblogs.com/Abnerzj/p/3819421.html

最近碰到一个问题,需求如下:

需求:在某个storyboard中有一个单独的控制器VC(没有连线),在storyboard中给此VC随便拖几个控件在上面,同时自定义一个类绑定此VC,问如何获取到此VC并且显示storyboard中此VC设置的界面。如下图:

 

1,首先要知道是哪个storyboard,先介绍一下storyboard的三个方法:

1> 下面的方法表示通过storyboard的名字从某个包中获取(一般设置为nil表示从主包中获取)storyboard
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil

2> 此方法获取到storyboard中初始的控制器
- (id)instantiateInitialViewController 

3> 此方法表示通过控制器的identifier获取到此控制器,新版本的Xcode用Storyboard ID来表示某个控制器的identifier
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier; 

好了,从上面的三个方法应该很多朋友都知道怎么获取Storyboard中单独的控制器了。

 

2,在storyboard中设置此单独的VC的identifier,即Storyboard ID,用于区分storyboard中的控制器,如下图

                 

 

3,在类中调用storyboard中的-instantiateViewControllerWithIdentifier:方法获取次单独的VC

ZJDuLiController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DuLi"]

 

4,push或modal出次VC即可

[self.navigationController pushViewController:vc animated:YES];

最终效果如下:

                              

 

原创文章,转载请注明出处:http://www.cnblogs.com/Abnerzj/p/3819421.htm

阅读(284) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~