关于页面跳转的几种方法与比较

跳转1.storyboard内的简单的跳转

  在页面1内拖入一个button,右击button,连线到要跳转的页面

跳转2.storyboard内使用控制器之间连线的segue来进行跳转

  在页面1内右键拖线到要跳转的页面内,然后给中间的连线,设置一个identifier,

  在跳转的时候使用 [self performSegueWithIdentifier:"identifier" sender:nil];
  就实现跳转,并且还有prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender方式,实现跳转之间的传值

跳转3.storyboard内创建页面,使用导航栏跳转

  根据控制器的identifier获取得到页面以及控制器,使用[self.navigationController pushViewController:vc animated:YES]方法进行跳转
  tip:该方法跳转,跳转进入的控制器,会存在导航栏,使用self.navigationController的成员方法,

    并且配合self.navigationController.viewControllers可以pop到任何想要跳转返回的界面。

    用户可以点击返回,返回到上一个页面,方法4就无法做到跳转。

跳转4.storyboard内创建页面,使用show方法跳转

  根据控制器的identifier获取得到页面以及控制器,使用[self presentViewController:vc animated:YES completion:nil]方法进行跳转

  tip:该跳转方法,跳转进入的控制器内,不存在导航栏,需要使用[self dismissViewControllerAnimated:YES completion:nil]方法返回上一页

跳转5.XIB创建页面,使用show方法跳转

  直接使用alloc,init方法或者new方法创建控制器,使用[self presentViewController:vc animated:YES completion:nil]方法进行跳转

跳转6.XIB创建页面,使用导航栏跳转

  直接使用alloc,init方法或者new方法创建控制器,使用[self.navigationController pushViewController:vc animated:YES]方法进行跳转
  tip:同跳转3

跳转7.纯代码创建页面,使用show方法跳转

  直接使用alloc,init方法或者new方法创建控制器,使用[self presentViewController:vc animated:YES completion:nil]方法进行跳转

跳转8.纯代码创建页面,使用导航栏跳转

  直接使用alloc,init方法或者new方法创建控制器,使用[self.navigationController pushViewController:vc animated:YES]方法进行跳转
  tip:同跳转3

跳转9.tabbarController实现页面的跳转

  通过各种方法创建好控制器之后,添加到数组内,并且赋值给self.tabbarController.viewControllers

 
原文地址:https://www.cnblogs.com/thxios/p/4894873.html