2011-03-24 60 views
0

我知道,你可以从一个视图控制器使用中间级切换到另一个,如this example看到。在不同的ViewController中切换到新的ViewController?

我想知道的是,有没有办法切换到从另一个视图控制器有不同的看法直接控制?比如,在当前的视图控制器中加载视图,然后释放你之后立即使用的视图?

谢谢。

+0

将这样做的目的是是什么呢?你最终的目标是什么? – drewag 2011-03-24 23:07:39

回答

0

我想你问的是如何留住1个视图控制器。

你可以做的是,当你添加新的视图控制器,将其添加到您的父视图控制器和删除当前视图控制器。

0

使用的UINavigationController是单向的:[navigationController pushViewController:animated:]。另一种“官方”方式是将下一个视图显示为模式视图:[someVC presentModalViewController:],但自iOS 6开始不推荐使用。

iOS 6的方法是: - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

0
var currentVC:UIViewController! 
let firstVC = yourViewcontroller1() 
let secondVC = yourViewcontroller2() 
func setupChildViewControllers(){ 
    self.addChildViewController(firstVC) 
    self.addChildViewController(secondVC) 
    self.view.addSubview(firstVC.view) 
    self.currentVC = firstVC 
} 

func replaceController(oldVC:UIViewController,newVC:UIViewController){ 
    self.addChildViewController(newVC) 

    self.transitionFromViewController(oldVC, toViewController: newVC, duration: 0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: nil) { (finished) -> Void in 
     if finished { 
      newVC.didMoveToParentViewController(self) 
      oldVC.willMoveToParentViewController(nil) 
      oldVC.removeFromParentViewController() 
      self.currentVC = newVC 
     }else{ 
      self.currentVC = oldVC 
     } 
    } 
} 
相关问题