单击NavigationView中嵌入的弹出框后,如何查看最新的子视图?

时间:2011-11-21 12:29:38

标签: iphone ios uinavigationcontroller popover

单击按钮时,会出现NavigationView中嵌入的popoverView。 我的代码如下:

  -(IBAction)myStuffPOP:(id)sender
   {
    if(myStuffListViewController ==nil)
    {        
        myStuffListViewController = [[MyStuffListViewController alloc] init]; 
    }
    UINavigationController *navcontroller=[[[UINavigationController alloc] initWithRootViewController:myStuffListViewController] autorelease];
 // Here we create popover controller.
    mystuffPopoverView =  [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
    CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];

    popoverRect.size.width = MIN(popoverRect.size.width, 100);
    popoverRect.size.height = 40;

    [mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    [navcontroller setNavigationBarHidden:NO];

} 

在PopoverView的NavigationView中:

1st subView ---> 2nd SubView ---> 3rd Subview

如果我触摸3rd SubView,PopoverView就会消失。

我的问题是:

当我再次点击按钮时,我想看到最新的视图 - 3rd SubView not 1st SubView.

2 个答案:

答案 0 :(得分:1)

无需每次都创建UINavigationController。保存方式与MyStuffListViewController

相同
if ( myNavigationController == nil )
    myNavigationController = [[[UINavigationController alloc]     initWithRootViewController:myStuffListViewController] autorelease];

答案 1 :(得分:1)

  1. 在.h文件中声明UINavigationController *navcontroller;
  2. 仅使用根视图控制器创建on navcontroller, 例如,在viewDidLoad方法中。

    - (void)viewDidLoad {     
        myStuffListViewController = [[MyStuffListViewController alloc] init]; 
        navcontroller=[[UINavigationController alloc] initWithRootViewController:myStuffListViewController]; }
    
  3. 使用现有导航堆栈显示UIPopoverController

    -(IBAction)myStuffPOP:(id)sender    {
        //Here we create popover controller.
        mystuffPopoverView =  [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
        CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
    
        popoverRect.size.width = MIN(popoverRect.size.width, 100);
        popoverRect.size.height = 40;
    
        [mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp
    animated:YES];
        [navcontroller setNavigationBarHidden:NO]; }
    
  4. 不要忘记release个对象

    - (void)dealloc {   
        [myStuffListViewController release];
        [navcontroller release];
    }