[IOS]页面跳转 相关

来源:互联网 发布:淘宝卖家密码修改 编辑:程序博客网 时间:2024/04/27 08:06

[IOS]页面跳转 相关


用伪代码只记方法关键,过程能省我就省了,基本方法有三

      有两个继承于UIViewController的类:  FristVC 和SecondVC.

效果: 

      在FristVC的View中放一个ButtonOne,点击后跳转至SecondVC的View;在SecondVC的View上放一个ButtonTwo ,点击后返回FristVC的View。


方法之一:

@property (strong,nonatomic)SecondVC *secondView;//FristVC部分-(void)buttonOneInside: (id)sender{      self.secondView = [[SecondVC alloc] initWithNibName:@ “SecondVC” bundle:nil ]      [self.view addSubView:self.secondView];}//SecondVC部分-(void)buttonTwoInside: (id)sender{      [self.view removeFromSuperView];}

方法之二:

//FristVC部分-(void)buttonOneInside: (id)sender{      self.secondView = [[SecondVC alloc] initWithNibName:@ “SecondVC” bundle:nil ]      [self presentViewController:self.secondview                                   animated:YES                                completion:^{}]; }//SecondVC部分-(void)buttonTwoInside: (id)sender{      [self dismissViewControllerAnimated:YES completion:^{}];}

方法之三:

导航条跳转 UINavigationController

      UINavigationController相当于是一个容器,然后将所有的view都放到这个容器里面去,有一对方法push和pop 用于把View推进和推出。

//代理 。m部分:self.fristView = [[FristVC alloc] initWithNibName:@ “FristVC” bundle:nil ]//把rootView设置为firstViewUINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.fristView]; //FristVC部分-(void)buttonOneInside: (id)sender{      self.secondView = [[SecondVC alloc]initWithNibName:@ “SecondVC” bundle:nil ]      [self.navigationController pushViewController:self.secondView animated:YES];}//SecondVC部分-(void)buttonTwoInside: (id)sender{      [self.navigationController popViewControllerAnimated:YES];}
0 0
原创粉丝点击