ios页面跳转

reference:http://blog.youkuaiyun.com/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];

有待验证

 

 
 

转载于:https://www.cnblogs.com/lucky-star-star/p/5627145.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值