segue storyboard condition issue

回眸只為那壹抹淺笑 提交于 2019-12-24 08:32:16

问题


I have this two controller liked by segue:

My problem is that:

when I tap on selected table view'cell in general I have to follow the segue and so go to other controller , but if a specific condition is true I have to show ad alert view and so I don't follow the segue and so don't go to those controller.

In this way when I tap on selected cell I go always on the other controller.

How do I solve this problem?


回答1:


if you override this function segue wont continue if you return false, this gives you the oportunity to show a warning under certain conditions, after that you can performSegueWithIdentifier("segueidentifier", sender: self), and your good to go.

override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject?) -> Bool {

    if identifier == "segueidentifier" {
        //show warning and perform segue with this identifier on the accept button listener.
        return false 
    }
}
    return true
}



回答2:


You can add a segue from one controller to another without specifying exact view which triggers the segue. Then just check your condition in didSelectRow method and call performSegue method if you need to show new view controller:

if condition {
   performSegue(withIdentifier: "MySegueIdentifier", sender: nil)
}
else {
   //show ad here
}

To add a segue between controllers just drag with right mouse button from one controller to another and pick "Show".

Then select segue and add a string identifier for it:

Make sure you use the same string in the code when you call performSegue method.



来源:https://stackoverflow.com/questions/40137794/segue-storyboard-condition-issue

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