Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 运行自定义展开序列时EXC\u错误\u访问_Ios_Swift_Xcode_Segue - Fatal编程技术网

Ios 运行自定义展开序列时EXC\u错误\u访问

Ios 运行自定义展开序列时EXC\u错误\u访问,ios,swift,xcode,segue,Ios,Swift,Xcode,Segue,我正在尝试使用此工作流构建一个iOS应用程序:在本例中,用户将看到一个主视图,即ViewController,然后可以单击UITableViewCell,以便通过自定义segue(标识符为doneSegueToCountryDetail的SegueRight)定向到DetailCountryViewController。这很好用。然后,当用户向右滑动(使用滑动手势识别器)时,应将其释放并发送回ViewController。此外,对于自定义segue,SegueLeft带有标识符segueCoun

我正在尝试使用此工作流构建一个iOS应用程序:在本例中,用户将看到一个主视图,即ViewController,然后可以单击UITableViewCell,以便通过自定义segue(标识符为doneSegueToCountryDetail的SegueRight)定向到DetailCountryViewController。这很好用。然后,当用户向右滑动(使用滑动手势识别器)时,应将其释放并发送回ViewController。此外,对于自定义segue,SegueLeft带有标识符segueCountryDetailToMain)。 但是,这会冻结应用程序(在ViewController已经显示之后,所以这可以工作),几秒钟后,它会因代码EXC_BAD_ACCESS而崩溃。以下是我目前的代码:

Swift 3

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    public func tableView(_ tableView: UITableView, didSelectRowAt
            indexPath: IndexPath){

        let indexPath = tableView.indexPathForSelectedRow
        let currentCell = tableView.cellForRow(at: indexPath!) as UITableViewCell!

        tableView.deselectRow(at: indexPath!, animated: true)

        titleToPass = currentCell?.textLabel?.text?.capitalized

        if tableView == self.tableViewDone {
            performSegue(withIdentifier: "doneSegueToCountryDetail", sender: self)
        } else if tableView == self.tableViewWish {
            performSegue(withIdentifier: "wishSegueToCountryDetail", sender: self)
        }
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "doneSegueToCountryDetail" || segue.identifier == "wishSegueToCountryDetail" {
            if let exitVC = segue.destination as? DetailCountryViewController {
                exitVC.titleVar = titleToPass
            }
        }
    }

    @IBAction func unwindToMainContent(segue:UIStoryboardSegue) {

    }
}

class SegueFromLeft: UIStoryboardSegue
{
    override func perform()
    {
        print("SegueFromLeft called")
        let src = self.source
        let dst = self.destination

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)

        UIView.animate(withDuration: 0.25,
                       delay: 0.0,
                       options: UIViewAnimationOptions.curveEaseInOut,
                       animations: {
                        dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
        },
                       completion: { finished in
                        src.present(dst, animated: false, completion: nil)
        }
        )
    }
}

class DetailCountryViewController: UIViewController {
    var titleVar = ""

    @IBAction func swipeBack(_ sender: UISwipeGestureRecognizer) {
        performSegue(withIdentifier: "segueCountryDetailToMain", sender: self)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
它在SegueLeft的perform()函数中在线崩溃

completion: { finished in
        src.present(dst, animated: false, completion: nil) }
我似乎找不到错误。当它崩溃时,src变量设置为DetailCountryViewController,dst设置为ViewController。错误在哪里

更新1 所以,我通过改变上面发生碰撞的那一行来“修复”这个问题

completion: nil
因此,据我从文档中了解,当ViewController成功显示时,不会调用任何内容。然而,当我现在再次返回DetailCountryViewController时,它再次崩溃。这一次,因为DetailCountryViewController已在ViewController中显示,我将再次尝试显示它(当然)。 因此,我现在知道,我选择的完成处理程序src.present可能不正确,或者我应该使用其他东西。但是什么呢?我是否必须解雇任何地方的控制器,或者