如何设置 Popover 视图以正确关闭
经过一番工作后,我得到了一个弹出视图,其中显示了一个自定义 uiview,显示正确。 当您点击弹出窗口视图之外时,它会按预期关闭,但是我也希望它在点击其中的按钮时关闭,有谁可以帮助我吗?努力寻找简明指南。
After some work I've got a popover view displaying a custom uiview inside of it appearing properly.
When you tap outside of the popover view it dismisses as expected, however I'd also like it to dismiss when a button inside it is tapped, is there any one who can help me with that? Struggling to find a concise guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要手动关闭弹出窗口,您需要保留对它的引用。一个好地方是在显示弹出窗口的视图控制器中。
要让内容视图控制器内的按钮告诉原始视图控制器(呈现弹出窗口)关闭弹出窗口,两种可能的方法是委托+协议或 NSNotificationCenter。
下面的示例代码使用 NSNotificationCenter 。
在呈现弹出窗口的视图控制器(“PresenterViewController”)的 .h 中,为 popoverViewController 添加属性:
在 PresenterViewController 的 .m 中:
在内容视图控制器中,实现按钮点击方法,如下所示:
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.
The example code below uses NSNotificationCenter.
In the .h of the view controller that presents the popover ("PresenterViewController"), add a property for the popoverViewController:
In the .m of PresenterViewController:
In the content view controller, implement the button tap method as follows: