Errors while using shouldPerformSegue(withIdentifier, sender) method in swift4

怎甘沉沦 提交于 2019-12-02 10:17:40

If you want to perform logic to decide if a segue should be "performed" or not, you need to override shouldPerformSegue. This will allow the OS to (1) kick off things properly and (2) for you to be able to decide if the segue gets done.

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    if [criteria met to perform segue] {
        return true
    } else {
        return false
    }
}

First of all, you’re attempting to provide a closure as the third parameter to the method, which doesn’t take three parameters, doesn’t take a closure as a parameter at all and this method shouldn’t be called by your code at all.

Second, implement some sort of Boolean flag ‘isSegueActive’ which would be set to ‘false’ or ‘true’ depending on the condition in the related button action.

Third, override ‘shouldPerformSegue’ in your view controller and make it return the value of ‘isSegueActive’.

That way when performing the segue, your view controller will call ‘shouldPerformSegue’ to know whether a segue should be performed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!