1

单击按钮时,会出现嵌入在 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.

4

2 回答 2

1

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

if ( myNavigationController == nil )
    myNavigationController = [[[UINavigationController alloc]     initWithRootViewController:myStuffListViewController] autorelease];
于 2011-11-21T12:40:55.643 回答
1
  1. UINavigationController *navcontroller;在 .h 文件中声明
  2. 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];
    }
    
于 2011-11-21T12:49:25.603 回答