Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom

一、视图切换类型介绍
在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的。在iphone中,segue有:push,modal,和custom三种不同的类型,这些类型的区别在与新页面出现的方式。而在ipad中,有push,modal,popover,replace和custom五种不同的类型。
modal

最常用的场景,新的场景完全盖住了旧的那个。用户无法再与上一个场景交互,除非他们先关闭这个场景。是在viewController中的标准切换的方式,包括淡出什么的,可以选切换动画。Modalview:就是会弹出一个view,你只能在该view上操作,而不能切换到其他view,除非你关闭了modalview.Modal View对应的segue type就是modal segue。
当user在弹出的modalview里操作完后,就应该dismiss the modal view scene然后切换回the originalview.

*Modal:Transition to another scene for the purposes of completing a task.


push

push类型一般是需要头一个界面是个Navigation Controller的。是在navigation View Controller中下一级时使用的那种从右侧划入的方式。该segue type是和navigation viewcontrollers一起使用。

*Push:Create a chain of scenes where the user can move forward or back.


popover(iPad only)
popover 类型,就是采用浮动窗的形式把新页面展示出来
*Popover(iPad only):Displays the scene in a pop-up “window” over top of the current view.

 
Replace (iPad only):
替换当前scene,
*Replace the current scene with another. This is used in some specialized iPad viewcontrollers (e.g. split-view controller).

custom

就是自定义跳转方式。在Storyboard中使用自定义的segue类型
*Custom:Used for programming a customtransition between scenes.


一 、简述
Storyboard是你可以用来定义用户界面的一种新的方式,像xib。
与xib不同的是它可以同时管理多个ViewController,而且可以在Storyboard中配置ViewController 之间的跳转关系。

 
二、 Scene之间的数据传递
在Storyboard中使用自定义的segue类型  系统用prepareForSegue:sender:这个方法。如果你想从一个界面切换到里另一个界面的时候传递数据,你应该override这个方法。
想把数据  NSString A_data   从AController传到BController,则在BController中 
@property 一个NSString data
然后在AController中添加方法

<span style="font-size:14px;">- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"The segue id is %@", segue.identifier );
    UIViewController *destination = segue.destinationViewController;  
    if ([destination respondsToSelector:@selector(setData:)])
    {
        [destination setValue:@"这是要传递的数据" forKey:@"data"];
    }   
}</span>
之后,Bcontroller中的data属性,就接收到数据了。
 
五、ViewController之间的跳转
1、如果在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。
2、如果目标ViewController存在Storyboard中,但是没有segue。你可以通过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,然后再用你想要的方式实现跳转,如:压栈。
3、如果目标ViewController不存在,那就去创建它吧。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值