您的位置:首页 > 移动开发 > IOS开发

iOS开发中视图相关的小笔记:push、modal、popover、replace、custom

2015-11-05 15:10 501 查看
在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。

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

是在navigation View Controller中下一级时使用的那种从右侧划入的方式

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

replace类型就是替换

custom就是自定义跳转方式啦。

视图之间的数据传递

当你从当前场景中触发一个segue的时候,系统会自动调用prepareForSegue:sender:这个方法。如果你想从一个界面切换到里另一个界面的时候传递数据,你应该override这个方法。

A -> B

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

@property 一个NSString data

然后在AController中添加方法

- (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"];

    }   

}

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

ViewController之间的跳转

1、如果在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。

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

3、如果目标ViewController不存在,那就去创建它吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: