如何在点击按钮的swift中解除popover?

时间:2017-10-07 19:51:37

标签: ios swift popover

我创建了popover,其中有两个按钮。我想在点击弹出窗口中的按钮时解除popover。

这是我的代码: 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:

@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
      }

1 个答案:

答案 0 :(得分:4)

致电

dismiss(animated: true, completion: nil)

在这些方法中,这将解除呈现的弹出窗口。