Warning: Attempt to present on <…> which is already presenting (null)

后端 未结 4 853
孤城傲影
孤城傲影 2021-02-07 02:00

I have a long press gesture set on a UITableView that presents a UIAlertController containing the cell\'s text. When the UIAlertController

4条回答
  •  粉色の甜心
    2021-02-07 02:36

    For some reason, both pieces of code are executing in the if

    That should have rung alarm bells for me. It is impossible that both the if and the else should run. This code must be running twice.

    That is because you are not testing the state of the gesture recognizer. A long press g.r. sends its action message twice. You are running this code both on the long press and on the release. You need to test the state of the g.r. so that you don't do that. Example:

    @IBAction func longPressedView(g: UIGestureRecognizer) {
        if g.state == .Began {
            // ... do it all here
        }
    }
    

提交回复
热议问题