NavigationController:更换推的UIViewController与另一个

问题描述:

为了更好地理解以下问题的,下面是说明我的应用程序的结构的小客厅:http://grab.by/6jXhNavigationController:更换推的UIViewController与另一个

所以,基本上我有一个基于导航的应用程序,它使用NavigationController的“pushViewController”方法显示视图A和B.

我想完成的是从视图A过渡到视图B,反之亦然。 例如,用户在主视图中按下“A”按钮,使用NavigationController推送视图A.在这个视图中,用户可以按下按钮“Flip to B”,视图B替换NavigationController栈上的视图A(视觉上,这是通过翻转过渡完成的)。如果用户按下视图B上的“后退”按钮,则会再次显示主视图。 要保存已用内存,当前未显示的视图(控制器)必须进行处理/卸载/删除。

什么是适当的方法来做到这一点?我需要某种类型的ContainerViewController吗?还是可以不用?

谢谢。

,您可以拨打ContainerViewController类,然后把它想:

ContainerViewController *containerViewController = [[ContainerViewController alloc] initWithFrontView: YES]; 
[self.navigationController pushViewController: containerViewController animated: YES]; 
[containerViewController release]; 

其中类可能类似于:

- (id)initWithFrontView: (BOOL) frontViewVisible { 
    if (self = [super init]) { 
     frontViewIsVisible = frontViewVisible; 

     viewA = [[UIView alloc] init]; 
     viewB = [[UIView alloc] init]; 

     if (frontViewIsVisible) { 
      [self.view addSubview: viewA]; 
     } 
     else { 
      [self.view addSubview: viewB]; 
     } 


     //add a button that responds to @selector(flipCurrentView:) 
    } 
    return self; 
} 

- (void) flipCurrentView: (id) sender { 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.75]; 
     [UIView setAnimationDelegate:self]; 

     if (frontViewIsVisible == YES) { 
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: self.view cache:YES]; 
      [viewA removeFromSuperview]; 
      [self.view addSubview: viewB]; 
     } else { 
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView: self.view cache:YES]; 
      [viewB removeFromSuperview]; 
      [self.view addSubview: viewA]; 
     } 

     [UIView commitAnimations]; 

     frontViewIsVisible =! frontViewIsVisible; 
    } 
(因为你可以用正面或背面图上顶推)

不要忘记照顾内存管理。我还建议你看看http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html--这几乎就是你要找的。