zoukankan      html  css  js  c++  java
  • ios页面跳转

    reference:http://blog.csdn.net/engandend/article/details/11706323

    目前,就我所学到的内容,页面跳转有三种方法  

    一、直接推到下一个页面

           定义好两个页面之后,在第一个界面添加一个button 并且对button实现changView方法

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. -(IBAction)chang:(id)sender;  

    在 .m 文件里面实现
    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. -(void)chang:(id)sender{  
    2.     second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];  
    3.     [self presentViewController:secondview animated:YES completion:^{}];  
    4. }  

    备注:second是第二个页面   这样就实现了第一种页面跳转,这种跳转的效果是从下面往上移动的效果

       页面返回

              当然,用这种方法来推到下一个页面,有时候还需要返回到上一个页面的时候,就需要额外实现一个方法 ,与  presentViewController:  对应的返回方法为dismissViewControllerAnimated:   在第二个页面添加一个button  对其添加一个方法,方法的实现里面加上这一行代码就可以了

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [self presentViewController:firstview animated:YES completion:^{}];  
    2. [self dismissViewControllerAnimated:YES completion:^{}];  

    二、导航条跳转 UINavigationController

           这个跳转方法需要的是借用UINavigationController来实现

        UINavigationController相当于是一个容器,然后将所有的view都放到这个容器里面去

            在代理.m 文件里面添加以下代码   

    就是添加一个导航条  

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. UINavigationController *_navTest = [[UINavigationController alloc] initWithRootViewController:_viewController];  

    导航条加进去之后第一个页面要加载哪一个?  用这一行代码来实现,并且是替换掉以前的那一个

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. self.window.rootViewController = _navTest;  

    可以选择添加的代码:在  .m  加载的方法里面  添加这个页面的titile
    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [self setTitle:@"first"];  

    实现的方法
    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. -(void)chang:(id)sender{  
    2.     second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];  
    3.     [self.navigationController pushViewController:secondview animated:YES];  
    4. }  

               页面跳转之后,当然,自带的导航条上就有一个返回按钮,但是如果我们要自己代码实现这一个放回到上一个页面的话,我们用dismissViewControllerAnimated:是不能实现的,咋这里需要用的是popViewControllerAnimated  具体代码的实现为:
    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [self.navigationController popViewControllerAnimated:YES];  

    这样就完成了  两种页面的跳转和返回了

    第三种,将其他页面直接加到当前页面

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. view1=[[view21 alloc]initWithNibName:@"view21" bundle:nil];  
    2.     [mainScr addSubview:view1.view];  
    3.     view1.view.frame=CGRectMake(0, 0, 1024, 768);  


    其对应的返回到前一个页面的方法可以使用

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [view1 removeFromSuper];  
    但是具体和addsubview是不是对应的我还在研究中····

    第四种: 

    introView = [[CompanyIntroViewController alloc]init];

    [self.view insertSubview:introView.view aboveSubview:backImageView];

    有待验证

     
     
  • 相关阅读:
    django基础知识之分页:
    django基础知识之后台管理Admin站点:
    django基础知识之上传图片:
    django基础知识之管理静态文件css,js,images:
    《机器学习》周志华 习题答案5.5
    《机器学习》周志华 习题答案3.6
    《机器学习》周志华 习题答案3.5
    PCA和LDA降维的比较
    Anaconda安装更新库
    《机器学习》周志华 习题答案3.3
  • 原文地址:https://www.cnblogs.com/lucky-star-star/p/5627145.html
Copyright © 2011-2022 走看看