gpt4 book ai didi

已经呈现的 iOS 8 Xcode 6.1 Swift prepareForSegue Controller (空)

转载 作者:行者123 更新时间:2023-11-29 02:15:26 25 4
gpt4 key购买 nike

我收到以下警告:

Warning: Attempt to present StartViewController: 0x7ff418e1be30 on StartViewController: 0x7ff418c4ab50 which is already presenting (null)

我的代码:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// 1
if segue.identifier == "Add" {

let alertController: UIAlertController = UIAlertController(title: "Choices", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
let button1action: UIAlertAction = UIAlertAction(title: "First Choice", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
self.performSegueWithIdentifier("first", sender: self)
})
let button2action: UIAlertAction = UIAlertAction(title: "Second choice", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in
self.performSegueWithIdentifier("second", sender: self)
})
alertController.addAction(cancelAction)
alertController.addAction(button1action)
alertController.addAction(button2action)


self.presentViewController(alertController, animated: true, completion: nil)

}

如果我按下 ViewController 中的“添加”按钮,将会弹出警报,同时也会弹出警告消息。 Controller 在代码的最后一行调用自己,但我没有解决办法。有人可以帮助我吗?

最佳答案

如果您处于 prepareForSegue 中,则意味着您已经触发了 segue,因此某些 View Controller 的呈现已经开始。

您不应该从 prepareFromSegue 调用 presentViewController,而应使用它来设置 destination View Controller 。

对于这种情况,我认为当您添加时,您需要触发IBAction并将该代码移动到那里,而不是触发segue。

关于已经呈现的 iOS 8 Xcode 6.1 Swift prepareForSegue Controller (空),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28809508/

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