在UIButton上的rootUIView上加载新的UIView,从UIPopovercontroller单击

时间:2011-02-09 15:19:48

标签: ipad uipopovercontroller

我的应用程序非常简单,我没有使用splitview控制器。 我的问题是..如何从一个popovercontroller视图上的UIButton点击我的根视图控制器上加载一个新的uiview。

2 个答案:

答案 0 :(得分:0)

当您在弹出窗口中按下按钮时,您需要让根视图控制器首先关闭弹出窗口,然后您可以从根视图控制器显示新视图。

有关如何使用popver中的按钮解除弹出窗口的详细信息,请参阅我之前的回答"How to setup Popover views to dismiss properly"

主要思想是:

  

手动关闭弹出窗口,   你需要保持对它的引用。   在视野中,一个好地方   显示弹出窗口的控制器。

     

要在内容中包含按钮   视图控制器告诉原始视图   控制器(提出了   popover)解散popover,两个   可能的方式是   代表+协议或   NSNotificationCenter。


在上一个答案中,PresenterViewController是您的根视图控制器(呈现弹出窗口的控制器)。

您的情况的区别在于contentFooViewControllerDone方法(您将放在根视图控制器中):

- (void)contentFooViewControllerDone:(NSNotification *)notification
{
    // Button in content view controller was tapped, dismiss popover...
    [self.popoverController dismissPopoverAnimated:YES];

    // Load new view here...
    // Note: If intending to use presentModalViewController 
    // (instead of addSubView), you might need to set animated to NO
    // for above popover dismissal (otherwise presentModal will do nothing) 
    // or use performSelector:withObject:afterDelay to present new 
    // view controller to animate both dismiss and present.
}

答案 1 :(得分:0)

[[NSNotificationCenter defaultCenter] 
            addObserver:self
            selector:@selector(contentFooViewControllerDone:)
            name:@"contentFooViewControllerDone" 
            object:popoverController.contentViewController];



- (void)contentFooViewControllerDone:(NSNotification *)notification
{
    // Button in content view controller was tapped, dismiss popover...
    [self.popoverController dismissPopoverAnimated:YES];
}

- (void)dealloc 
{
    //stop listening for notifications and release popoverController...
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [popoverController release];
    [super dealloc];
}

- (IBAction)dismissButtonTapped
{
    [[NSNotificationCenter defaultCenter] 
        postNotificationName:@"contentFooViewControllerDone" object:self];
}