• IOS开发之——使用Segue在StoryBoard之间切换


    使用Segue能够在ViewController之间来回切换,以下就来说下切换方法:

    1. 使用点击button进行切换

    直接上图,在须要切换的View属性界面,点击Modal然后拉到前一个view界面或者是Button上



    2. 手动进行跳转

    假设拉到了Button的TouchUpInside上,那么点击左側button的时候就会切到右边的View,假设拉到了view上,就会连接Manual,在代码中实现跳转


    设置Segue的Indentifier属性:


    代码中手动进行跳转:

    //在viewDidAppear里面加入触发segue进行自己主动跳转
    -(void)viewDidAppear:(BOOL)animated
    {
        [self performSegueWithIdentifier:@"drawecg" sender:self];
    }

    注:在ViewDidLoad实现跳转无效


    3. 怎样跳转到随意一个页面

    在有可能进行上级跳转的ViewController文件里加上以下代码,函数名称任起:

    #pragma mark 定义这个函数,别的ViewController在Exit的时候就能直接跳到这了
    - (IBAction)goHome:(UIStoryboardSegue *)segue
    {
        [[segue sourceViewController] class];
    }
    

    在想要跳转view的Exit上右键,选择这个goHome函数,拉到想要运行的button上,就能够实现跳转了


    也可代码实现返回上一个页面,注销当前页面:

    -(void)lastPage
    {
        NSLog(@"点击了上一个视图button");
        [self dismissViewControllerAnimated:YES completion:^(void){
            
            // Code
            
        }];
    }


    也可这样实现:

     // 获取故事板
     UIStoryboard *board = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    
     // 获取故事板中某个View    
     UIViewController *next = [board instantiateViewControllerWithIdentifier:@"Second"];
    
     // 跳转    
     [self presentModalViewController:next animated:YES];


    当然,假设你使用Navigation Controller,使用Push进行连接,就不是上面的代码进行跳转了:

    跳转到LandscapeViewController

    //打开一个横屏界面
    - (IBAction)openLandscapeControl:(id)sender {
        LandscapeViewController *control = [[LandscapeViewController alloc]initWithNibName:@"LandscapeViewController" bundle:nil];
        
        [self.navigationController pushViewController:control animated:YES];
    }
    使用pop返回上一个View
    //返回前一页
    - (IBAction)clickBack:(id)sender {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    





  • 相关阅读:
    git 常用命令
    centos 7 mini 安装
    python打印杨辉三角
    python 求100内的素数/质数
    字符串与bytes
    format
    Python字符串格式化
    数据结构
    ARM工作模式
    C语言实现字符串逆序输出
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3782630.html
Copyright © 2020-2023  润新知