gpt4 book ai didi

ios - UIPopoverController popoverControllerDidDismissPopover 不起作用

转载 作者:行者123 更新时间:2023-11-30 14:05:25 25 4
gpt4 key购买 nike

我正在 iPad 上通过 uibutton 展示弹出 Controller 。我将 UIPopoverController 的委托(delegate)设置为主视图 Controller 。 “popoverControllerShouldDismissPopover”和“popoverControllerDidDismissPopover”都没有被调用。我错过了什么吗?

class MainVC: UIViewController,UIPopoverControllerDelegate

@IBAction func btnTPD(sender: UIButton) {

var vc = MyXIB(nibName: "MyXIB",bundle: nil)

var nav = UINavigationController(rootViewController: vc)

var popover = UIPopoverController(contentViewController: nav)
popover.delegate = self
popover.popoverContentSize = CGSize(width: 283, height: view.bounds.height * 0.6)
popover.presentPopoverFromRect(sender.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: false)

}

func popoverControllerShouldDismissPopover(popoverController: UIPopoverController) -> Bool {

println("SHOULD DISMISS")

return true

}

func popoverControllerDidDismissPopover(popoverController: UIPopoverController) {

println("DID DISMISS")

}

最佳答案

看来我的 UIPopoverController 实例(var popover)需要在“btnTPD”函数之外声明才能使委托(delegate)函数正常工作。

class MainVC: UIViewController,UIPopoverControllerDelegate {

var popover: UIPopoverController!

@IBAction func tapped(sender: UIButton) {

var vc = MyXIB(nibName: "MyXIB",bundle: nil)

var nav = UINavigationController(rootViewController: vc)

popover = UIPopoverController(contentViewController: nav)
popover.delegate = self
popover.popoverContentSize = CGSize(width: 283, height: view.bounds.height * 0.6)
popover.presentPopoverFromRect(sender.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: false)

}

func popoverControllerShouldDismissPopover(popoverController: UIPopoverController) -> Bool {

println("SHOULD DISMISS")

return true

}

func popoverControllerDidDismissPopover(popoverController: UIPopoverController) {

println("DID DISMISS")

}

}

关于ios - UIPopoverController popoverControllerDidDismissPopover 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32491670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com