[英]how to dismiss the popover with the bar button click
Hey there I have an in which I had to show the popover. 嘿,我必须在其中显示弹出窗口。 I could easily do this.
我可以轻松做到这一点。 When popover of other class is shown.
当显示其他类别的弹出窗口时。 There is titlebar with a bar button "Done" in this popover.
在此弹出框中有一个标题栏,带有一个“完成”的按钮。 I want to dismiss the popover with click of done button.
我想通过单击完成按钮来关闭弹出窗口。
how can i dismiss the popover with done button? 我如何用“完成”按钮关闭弹出窗口?
Thank you 谢谢
Did you tried to search for the solution? 您是否尝试寻找解决方案?
-(void) onDoneButtonClick {
[popover dismissPopoverAnimated:YES];
}
- (void)dismissPopoverAnimated:(BOOL)animated
is a method of UIPopoverController
class. - (void)dismissPopoverAnimated:(BOOL)animated
是UIPopoverController
类的方法。 In order to dismiss a popover programatically you have to keep a reference to the presented UIPopoverController
yourself. 为了以编程方式消除弹出窗口,您必须自己保留对所呈现的
UIPopoverController
的引用。
Here is a possible solution: 这是一个可能的解决方案:
In the view controller that popover loads, define a property. 在弹出窗口加载的视图控制器中,定义一个属性。
@interface MyViewController: UIViewController
@property (nonatomic, strong) UIPopoverController *popover;
@end
Before segue to popover is performed, store segue's popover controller. 在执行segue到popover之前,存储segue的popover控制器。
- (void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"mySegue"])
{
MyViewController *dvc = segue.destinationViewController;
dvc.popover = [segue popoverController];
}
}
When the button clicked, dismiss popover. 单击按钮后,关闭弹出窗口。
- (void)onButtonClick:(id)sender
{
[self.popover dismissPopoverAnimated:YES];
}
在simple popoverobj中,并在button事件上使用Simply方法。
[popoverobj dismissPopoverAnimated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.