gpt4 book ai didi

swift - 警告 : Attempt to present ViewController on ViewController which is already presenting ViewController

转载 作者:行者123 更新时间:2023-11-30 13:53:04 26 4
gpt4 key购买 nike

我有一个 View Controller ,其工具栏上有 3 个 UIButtons,可以打开一个新的 View Controller 作为弹出窗口。我在 Storyboard 中创建了 Segues 并选择了“Present as Popover”。弹出窗口可以工作,但是当用户在弹出窗口当前打开时点击另一个按钮时,我收到此错误:

Warning: Attempt to present <Fingerpainter.OpacityViewController: 0x79095110>  on <Fingerpainter.DrawingViewController: 0x7b278000> which is already presenting <Fingerpainter.BrushSizeViewController: 0x79573770>

有没有一种方法可以在打开新弹出窗口之前确保所有弹出窗口都已关闭?这是我在主 ViewController 中的prepareForSegue 方法(包含工具栏):

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let identifier = segue.identifier ?? ""
let popoverPresentationController = segue.destinationViewController.popoverPresentationController
popoverPresentationController!.delegate = self
switch identifier {
case Storyboard.BrushSizeSegueIdentifier:
if let brushSizeViewController = popoverPresentationController?.presentedViewController as? BrushSizeViewController {

// set properties in brushSizeViewController
}
case Storyboard.OpacitySegueIdentifier:
if let opacityViewController = popoverPresentationController?.presentedViewController as? OpacityViewController {
//set properties in opacityViewController
}
case Storyboard.ColorSegueIdentity:
if let colorViewController = popoverPresentationController?.presentedViewController as? ColorViewController {
//set properties in colorViewController
}
default:
break
}

}

最佳答案

Is there a way to like make sure all popovers are closed before opening a new one

情况正好相反。 的工作是确保当弹出窗口存在时,召唤另一个弹出窗口的按钮不可点击。您可以通过禁用按钮来做到这一点,但更常见的是,为了协调按钮的禁用与弹出窗口的存在,可以通过调整弹出窗口呈现 Controller 的 passthroughViews 来完成。

不幸的是,存在一个长期存在的巨大错误,即使将 passthroughViews 设置为 nil 也不会阻止工具栏按钮被点击。解决方法是延迟执行。我的许多弹出窗口代码添加了此类内容:

if let pop = popoverPresentationController {
delay(0.1) {
pop.passthroughViews = nil
}
}

(其中描述了延迟:https://stackoverflow.com/a/24318861/341994)。

关于swift - 警告 : Attempt to present ViewController on ViewController which is already presenting ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010692/

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