IOS随笔——页面跳转

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

一、直接推到下一个页面

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

-(IBAction)chang:(id)sender;

在 .m 文件里面实现
-(void)chang:(id)sender{
    second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];
    [self presentViewController:secondview animated:YES completion:^{}];
}

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

   页面返回

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

[self presentViewController:firstview animated:YES completion:^{}];
[self dismissViewControllerAnimated:YES completion:^{}];

二、导航条跳转 UINavigationController

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

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

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

就是添加一个导航条 

UINavigationController *_navTest = [[UINavigationController alloc] initWithRootViewController:_viewController];

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

self.window.rootViewController = _navTest;

可以选择添加的代码:在  .m  加载的方法里面  添加这个页面的titile
[self setTitle:@"first"];

实现的方法
-(void)chang:(id)sender{
    second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];
    [self.navigationController pushViewController:secondview animated:YES];
}

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

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


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

view1=[[view21 alloc]initWithNibName:@"view21" bundle:nil];
    [mainScr addSubview:view1.view];
    view1.view.frame=CGRectMake(0, 0, 1024, 768);


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

[view1 removeFromSuper];
但是具体和addsubview是不是对应的我还在研究中····



第四种: 

introView = [[CompanyIntroViewController alloc]init];

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

有待验证

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值