iOS基础iOS开发的正确姿势

iOS视图切换-push与modal混用

2016-01-11  本文已影响1538人  天天想念

方案1.先取消modal出来的窗口,取得对应的导航控制器,让后push新的控制器

  // 先取消原来的控制器
  [self dismissViewControllerAnimated:NO completion:nil];
  ViewController *VC1 = [[ViewController alloc] init];
  UIWindow *kwindow = [UIApplication sharedApplication].keyWindow;
  // 取得窗口的导航控制器
  UINavigationController *nav = (UINavigationController *)kwindow.rootViewController;
  NSLog(@"%@",nav.childViewControllers);
  MyNavigationController *lastNavc = [nav.viewControllers lastObject];
  // 导航控制器
  [lastNavc pushViewController: VC1 animated:YES];

方案2.modal窗口的基础上,继续modal方式出来一个导航控制器

  ViewController * vc1 = [[ViewController alloc] init];
  UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: vc1];
  [self presentViewController:nav animated:YES completion:nil];

  // 压入导航控制器栈的控制器,可以按照导航控制器的规则依次入栈和出栈。
  在vc1页面push出vc2
  ViewController * vc2 = [[ViewController alloc] init];
  [self.navigationController pushViewController: vc2 animated:YES];

  // 在导航控制器栈的任何一个页面都可以modal的方式直接返回
  [self dismissViewControllerAnimated:YES completion:nil];

方案3.push的基础上modal

  ViewController * vc2 = [[ViewController alloc] init];
  [self.navigationController pushViewController: vc2 animated:YES];

  ViewController * vc1 = [[ViewController alloc] init];
  [self presentViewController:vc1 animated:YES completion:nil];

上一篇下一篇

猜你喜欢

热点阅读