Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:如果条件不满足,则阻止segue执行_Ios_Swift_Segue - Fatal编程技术网

Ios Swift:如果条件不满足,则阻止segue执行

Ios Swift:如果条件不满足,则阻止segue执行,ios,swift,segue,Ios,Swift,Segue,目前,我正在应用程序中使用两种不同的ViewController,我们可以称它们为VC1和VC2。VC1显示注册表,UITableView的每一行中都有一个问题,并有一个编辑按钮。编辑按钮作为VC1和VC2的一个分段。VC2显示一个界面,允许用户编辑问题。我想编写应用程序,这样您就无法从VC1切换到VC2,除非您选择了要编辑的问题(行)。现在我已经设置了一些,但有可能是我倒过来的 在VC1中: // this method isn't called until VC2 segues back t

目前,我正在应用程序中使用两种不同的ViewController,我们可以称它们为VC1和VC2。VC1显示注册表,UITableView的每一行中都有一个问题,并有一个编辑按钮。编辑按钮作为VC1和VC2的一个分段。VC2显示一个界面,允许用户编辑问题。我想编写应用程序,这样您就无法从VC1切换到VC2,除非您选择了要编辑的问题(行)。现在我已经设置了一些,但有可能是我倒过来的

在VC1中:

// this method isn't called until VC2 segues back to VC1... so I don't know how
// to make sure that a selection has been made before pressing the button
@IBAction func editQuestion(segue:UIStoryboardSegue) {
        if let editQuestion = segue.sourceViewController as? VC2 {

        }
}
在VC2中:

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

    // check to make sure that user has completed all fields of question
    // if they haven't completed all fields, return false (do not segue)
    // else segue to VC1
}
在VC1中实现:

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
        if identifier == <your storyboard segue identifier> {

        }
    } 
override func shouldPerformSegueWithIdentifier(标识符:String,发送方:AnyObject?)->Bool{
如果标识符=={
}
} 

给你的故事板序列号一个标识符,然后你可以在VC1中执行检查,如果你不想让序列号发生,则返回false。

执行序列号之前的检查应该在VC1中进行,然后再调用PerformsgueWithIdentifier()。是的,我理解。但我不知道该怎么做。你有什么想法吗?我现在的结构不适合这种情况。你如何将segue称为VC2?它和故事板连在一起了吗?是的。两者都连接到故事板上。我按ctrl键单击VC1到VC2中的编辑按钮,并按ctrl键单击VC2中的保存按钮,将其发送到VC1中的editQuestion函数。所有的东西都连接好了,并且正确地进行了分段,我只是不知道在按下edit.question之前如何检查是否选择了一个问题。比方说,我在VC2的ViewDidAspect方法中检查了所选索引的值以获取一个问题。如果索引为-1,我知道没有选择任何内容。有没有办法通过ViewDidDisplay将其发送回VC1?所以我应该在VC1和VC2中都有一个ShouldPerformanceSeguiewithIdentifier?你能做到吗?我在VC2中使用了一个标识符。你应该在VC1中签入该标识符。你可以在VC2中使用它,但它只有在你已经切换到VC2之后才有用。我在VC1中有多个分段。它会知道要切换到哪个视图吗?是的,如果您覆盖它,它会为每个segue调用,如果您没有该标识符的任何代码,它就不会做任何事情。