美文网首页
ios界面跳转2016.5

ios界面跳转2016.5

作者: cj2527 | 来源:发表于2016-05-30 10:14 被阅读270次

1.可视化界面跳转之segue方式

在可视化界面storyboard里面几个View Controller之间的跳转。

自动segue

按钮控件直接拖线到目标控制器A。不需要验证,点击按钮就会直接跳转了。

手动segue

1.选中控制器,(View Controller顶部第一个图标)拖线到目标控制器B。可以做到验证一定条件才能跳转。点击连线的中间部位的图标,设置segue的identifier属性ID为secondRoad

2.在源控制器ViewController的.m文件的按钮事件编写代码

- (IBAction)openClick:(id)sender {
    
    [self performSegueWithIdentifier:@"secondRoad" sender:nil];
    
}

点击按钮就会跳转了。通常还会用到另外一个方法,用来传值,先新建ViewController类,命名为SecondViewController。在目标控制器B的custom class属性关联SecondViewController。在源控制器ViewController的.m文件编写代码

//跳转之前可以验证一些条件
-(void)prepareForSegue:(nonnull UIStoryboardSegue *)segue sender:(nullable id)sender{
  //获取目标控制器
  SecondViewController *destinationVc = segue.destinationViewController;
    if ([destinationVc isKindOfClass:[SecondViewController class]]) {
        destinationVc.name = @"登录名:admin";//通过属性传值
    }
    
}

2.在可视化界面storyboard之外的界面跳转

主要包括三种,
2.1在storyboard某一View Controller界面跳转到xib界面
2.2在storyboard某一View Controller界面跳转到代码界面
2.3在storyboard某一View Controller界面跳转到另外一个storyboard的某一界面

2.1界面跳转到xib

新建ViewController类,命名为SecondViewController,勾选xib文件一起创建,在xib文件中设置背景颜色。在源控制器ViewController的.m文件按钮事件编写代码

- (IBAction)openClick:(id)sender {
    SecondViewController *vc = [[SecondViewController alloc]init];
    [self presentViewController:vc animated:YES completion:nil];  
    //如果使用了导航控制器,就使用以下方法跳转
   //[self.navigationController pushViewController:vc animated:YES];
}

2.2界面跳转到代码界面

代码界面指没有xib文件,只有ViewController.h和ViewController.m两个文件。
新建ViewController类,命名为ThirdViewController,在它的viewDidLoad方法设置背景颜色。

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor grayColor]];
}

在源控制器ViewController的.m文件按钮事件编写代码

- (IBAction)openCodeView:(id)sender {
    ThirdViewController *vc =[[ThirdViewController alloc]init];
    [self presentViewController:vc animated:YES completion:nil];
}

2.3界面跳转到storyboard

新建一个storyboard文件,命名为other.storyboard
一开始是空白的,拖进一个View Controller界面,
设置它的背景颜色和storyboard ID属性为FourthViewController

在源控制器ViewController的.m文件按钮事件编写代码

- (IBAction)jumpToStoryboard:(id)sender {
    
    UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"other" bundle:nil];
    UIViewController *vc = [myStoryboard instantiateViewControllerWithIdentifier:@"FourthViewController"];
    [self presentViewController:vc animated:YES completion:nil];
    
}

相关文章

  • ios界面跳转2016.5

    1.可视化界面跳转之segue方式 在可视化界面storyboard里面几个View Controller之间的跳...

  • iOS集成ReactNative跳转、传值

    iOS跳转RN界面iOS跳转RN界面传值iOS跳转不同的RN界面(一)iOS跳转不同的RN界面(二)RN界面跳转到...

  • ios界面传值2016.5

    五种方法 1.属性传值,适合界面A到界面B的传值2.单例, 多个界面传值3.通知 , 界面A跳...

  • iOS App跳转设置界面、评分界面、三方app

    1. 跳转设置界面 1.1 iOS10以下跳转方法 1.1.1 iOS7之前 iOS系统版本 <= iOS7 , ...

  • Swift - 界面的跳转模式

    iOS开发中界面跳转有两种方式,上下跳转和左右跳转。 上下跳转_TO: letsecondViewControll...

  • swift 页面跳转

    iOS开发中界面跳转有两种方式,上下跳转和左右跳转。 上下跳转_TO: letsecondViewControll...

  • Swift实现IOS界面的跳转

    IOS开发中界面跳转有两种方式,上下跳转和左右跳转。 上下跳转_TO: let secondViewControl...

  • App跳转到权限设置界面

    iOS 10 App跳转到权限设置界面(iOS10之前就不各个记录了) 私有方法跳转 (1)跳转的URL(系统差异...

  • iOS Swift界面viewcontroller跳转

    iOS开发中界面跳转有两种方式,上下跳转和左右跳转。 上下跳转_打开: 上下跳转_关闭: 左右跳转_打开: (将新...

  • iOS10跳转设置

    由于苹果在iOS10中禁用了跳转设置界面(仅允许跳转app自身的设置界面),如果想跳转其他设置层级,比如关于本机,...

网友评论

      本文标题:ios界面跳转2016.5

      本文链接:https://www.haomeiwen.com/subject/cxnqdttx.html