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

发布于 2024-10-16 15:03:49 字数 109 浏览 6 评论 0原文

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

My application is very simple and i am not using the splitview controller.
My question is .. how can i load a new uiview over my root view controller on UIButton click from a popovercontroller view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

祁梦 2024-10-23 15:03:49

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

有关如何使用弹出窗口内的按钮关闭弹出窗口的详细信息,请参阅我之前的答案 “如何设置弹出窗口视图以正确关闭”

主要思想是:

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

将按钮放在内容中
视图控制器告诉原始视图
控制器(提出了
popover)关闭弹出窗口,两个
可能的方法是
委托+协议或
NS通知中心。

在上一个答案中,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.
}

You'll need to have the root view controller first dismiss the popover when the button is pressed in the popover and then you can present the new view from the root view controller.

For details on how to do the dismissal of the popover using a button inside the popver, see my previous answer "How to setup Popover views to dismiss properly".

The main idea is:

To dismiss the popover manually,
you'll need to keep a reference to it.
A good place would be in the view
controller that shows the popover.

To have the button inside the content
view controller tell the original view
controller (that presented the
popover) to dismiss the popover, two
of the possible ways are
delegate+protocol or
NSNotificationCenter.

In that previous answer, PresenterViewController is your root view controller (the one that presents the popover).

The difference in your case will be in the contentFooViewControllerDone method (which you would put in your root view controller):

- (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.
}
明明#如月 2024-10-23 15:03:49
[[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];
}
[[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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文