[英]How to dismiss popover in swift on button clicked?
I have created popover in which there are two buttons. 我创建了其中有两个按钮的弹出窗口。 I want to dismiss popover when button inside popover is clicked. 单击弹出框内的按钮时,我想关闭弹出框。
This is my code: FirstViewController : 这是我的代码:FirstViewController:
@IBAction func bar_button(_ sender: UIBarButtonItem) {
let vc = storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as!
SecondViewController
vc.preferredContentSize = CGSize(width: 200,height:80)
let navController = UINavigationController(rootViewController: vc)
navController.modalPresentationStyle = UIModalPresentationStyle.popover
let popover = navController.popoverPresentationController
popover?.delegate = self
popover?.barButtonItem = sender as! UIBarButtonItem
self.present(navController, animated: true, completion: nil)
}
SecondViewController : SecondViewController:
@IBAction func second_button(_ sender: UIButton) {
//want to dismiss popover when button clicked
}
@IBAction func second_button(_ sender: UIButton) {
//want to dismiss popover when button clicked
}
Call 呼叫
dismiss(animated: true, completion: nil)
inside those methods, This will dismiss the presented popover. 在这些方法中,这将消除显示的弹出框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.