从另一个视图关闭 UIPopoverController

发布于 2024-10-27 22:57:40 字数 137 浏览 6 评论 0原文

我在另一个视图中有一个名为 popoverUIPopoverController 。我想知道的是,如果在当前弹出窗口视图中按下 UIButton ,如何关闭弹出窗口?提前致谢。

I have a UIPopoverController named popover in another view. What I would like to know is, how can I dismiss the popover if a UIButton was pressed in the current popover view? Thanks in advance.

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

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

发布评论

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

评论(2

盛夏已如深秋| 2024-11-03 22:57:40

我总是觉得奇怪的是,UIViewController 通过它的“contentSizeForViewInPopover”属性知道它在弹出窗口中应该有多大,但不保留指向 UIPopoverController 本身的指针。我总是最终添加:

@property (nonatomic,assign) UIPopoverController* popover;

到我的 UIViewController 类中,并在创建弹出窗口时进行设置。然后,从 UIViewController 中的任何内容,我可以执行以下操作来关闭弹出窗口:

[popover dismissPopoverAnimated:YES];

I always found it odd that a UIViewController knows how big it should be in a popover through it's "contentSizeForViewInPopover" property, but doesn't keep a pointer to the UIPopoverController itself. I always end up adding:

@property (nonatomic,assign) UIPopoverController* popover;

to my UIViewController classes, and set that when creating the popover. Then from anything in that UIViewController, I can do this to dismiss the popover:

[popover dismissPopoverAnimated:YES];
痴骨ら 2024-11-03 22:57:40

您可以使用 NSNotification< /a> 告诉另一个视图关闭它的弹出视图。

用法示例:

// Add an observer that will respond to our notification.
[[NSNotificationCenter defaultCenter] addObserver:self // <- This is the object that will has the selector that we want to run (the same one we use in the next line).
                                         selector:@selector(doSomething:) // <- This is the selector we want to run.
                                             name:@"doSomethingNow" // <- This is notification name we will send to activate our observer's selector.
                                           object:nil]; // Don't worry about this for now.


// Post the notification. This has the same name as our observer above, so our 'doSomething' selector should be run.
[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNow" object:nil];


// the function specified in the same class where we defined the addObserver
- (void)doSomething:(NSNotification *)pNotification {
    NSLog(@"Received Notification..."); 
}

You could use an NSNotification to tell the other view to dismiss it's popover view.

Example usage:

// Add an observer that will respond to our notification.
[[NSNotificationCenter defaultCenter] addObserver:self // <- This is the object that will has the selector that we want to run (the same one we use in the next line).
                                         selector:@selector(doSomething:) // <- This is the selector we want to run.
                                             name:@"doSomethingNow" // <- This is notification name we will send to activate our observer's selector.
                                           object:nil]; // Don't worry about this for now.


// Post the notification. This has the same name as our observer above, so our 'doSomething' selector should be run.
[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNow" object:nil];


// the function specified in the same class where we defined the addObserver
- (void)doSomething:(NSNotification *)pNotification {
    NSLog(@"Received Notification..."); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文