IOS中切换视图中push、modal、popover、replace、custom

来源:互联网 发布:windows任务计划 编辑:程序博客网 时间:2024/05/21 01:58


在storyboard中、segue有几种不同的跳转类型、在iPhone与iiPad的开发中、segue的类型是不同的

在iPhone中、segue有:push、modal,和custom三种不同的类型、这些类型的区别在与新页面出现的方式。

在iPad中、segue有:push、modal、popover、replace和custom五种不同类型。


modal模态转换

最常用的场景、新的场景完全覆盖住了旧的场景、用户无法再与上一个场景交互、除非他们先关闭这个场景。

是在viewController中的标准切换方式、包括淡出、可以选切换动画。

Modalview:就是会弹出一个view,你只能在该view上操作,而不能切换到其他view、除非你关闭了modalview。

modalview 对应的segue type就是modal segue


Push类型一般是需要头一个界面是个Navigation Controller。

是在navigation View Controller中下一级使用的那种从右划入的方式、类似压栈、一层一层显示


popover类型、就是采用浮动窗的形式把新页面展示出来


replace类型就是替换


custom就是自定义跳转方式


视图之间的数据传递segue类型为push时

当你从当前场景中出发一个segue的时候、系统会自动调用perpareForSegue:sender:这个方法。如果你想从一个界面切换到另一个界面

的时候传递数据、你应该Override(重写、重载)这个方法。

例如 :A->B

想把数据NSString A_data 从AController,则在BController中

@property 一个NSString data

然后把在AController中添加方法

-(void)TurnToBViewController

{

//跳转方法

 [self performSegueWithIdentifier:@"TurnToBController" sender:self];

data=[你要显示到BController的界面的数据];

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender//传参方法

{

    if([segue.identifier isEqualToString:@"TurnToBController(跳转segue的identifier)"])

   {

    id segue = segue.destinationViewController;


    [segue1 setValue:data forKey:@"strForData"];//strForData 是在BController中定义的字符串、以此传参[例如、BController中的titlelab.text=strForData;]   

    }

}


之后,Bcontroller中的strForData属性,就接收到数据了。

ViewController之间的跳转
1、如果在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。最好选择Push方式、当你跳转后返回上级界面的时候不会出现代码错误。


2、如果目标ViewController存在Storyboard中,但是没有segue。你可以通过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,然后再用你想要的方式实现跳转,如:压栈。



0 0
原创粉丝点击