iOS:storyboard

------------Storyboard使用------------(available 5.0/xcode 4.2)

1、创建storyboard文件

2、配置 storyboard中的viewController
3、配置应用程序Info.plist文件中UIMainStoryboardFile ,值为storyboard的文件名(原来的NSMainNibFile不存在了)。

------------Segue的使用------------

--俩种控制器跳转segue触发方式:button-to-viewcontroller(隐式)  && viewcontroller-to-viewcontroller(显式);

--关键对象:UIStoryboardSegue(主要属性 sourceViewController + destinationViewController + identifier),当触发segue时,系统将完成下列操作:

1.实例化目标视图控制器;
2.实例化一个新segue对象,该对象持有所有的信息
3.调用源视图控制器的prepareForSegue:sender: (iOS 6新加了shouldPerformSegueWithIdentifier方法,允许判断是否跳转)

4.调用segue的 perform 方法将目标控制器带到屏幕上(不同类型modal,push,custom)。

--传递数据:在prepareForSegue:sender 方法里,利用UIStoryboardSegue属性引用目标控制器赋值。

--关于segue类型:modal,push,custom。

--自定义segue:1.子类化一个UIStoryboardSegue类XX;2.实现perform方法;3.对storyboard中的Segue进行设置(Style、Segue Class)。

******备注:

--1.模式视图跳转(modal类型)[self performSegueWithIdentifier:@"aabb" sender:self];的时候不能在viewDidLoad/viewwillappear中进行调用(whose view is not in the window hierarchy) 。

--2.storyboard 中ViewController之间的跳转(xib&storyboard):
a.如果当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。

b.如果目标ViewController存在Storyboard中,但是没有segue。你可以通过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,然后再用你想要的方式实现跳转,如:压栈。
c.如果目标ViewController不存在,那就去创建它(可以通过xib创建等)。

--3.关于控制器的返回:通过popViewController、dismissViewControllerAnimated等方法返回,如果想新建segue跳回去,返回到达的是一个新的控制器,不是原来的那个。

--4.创建控制器俩种方式

1.通过代码init/initWithNIb:bundle 

2.通过storyboad: 

UIStoryboard *story = [UIStoryboard storyboardWithName:@"sb的文件名" bundle:nil];   //加载storyboard文件
// 根据控制器在storyboard文件中storyboard id来创建
XXViewController *one = [story instantiateViewControllerWithIdentifier:@"控制器的storyboard id"]; 
XXOneViewController *one = [story instantiateInitialViewController];// 直接创建箭头所指的控制器(initial controller)

------------------------

参考:

http://blog.csdn.net/crazy__programmer/article/details/13508635 

http://blog.csdn.net/citysupervisor/article/details/11680963  

http://www.cnblogs.com/xszhao/p/3452306.html

你可能感兴趣的:(ios,storyboard)