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

前端 未结 2 553
走了就别回头了
走了就别回头了 2021-01-28 01:12

What I\'m trying to do:

  • checking a condition, if the condition is true, perform segue as normal. If condition is false, call the shouldPerformSegue method and retu
2条回答
  •  一个人的身影
    2021-01-28 01:51

    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.

提交回复
热议问题