如何解决错误“线程1:信号SIGABRT”?

时间:2019-10-13 17:10:45

标签: swift button uibutton

picture of the connection inspector

我创建了一个带有视图和按钮的ViewController。我已经在ViewController中将按钮声明为插座和Action。另外,我正在通过segue将第一个Viewcontroller的数据传递给第二个Viewcontroller。当我单击“取消”按钮,并执行回退到第一个ViewController时,我得到了错误

  

线程1:发出信号SIGABRT。

在传递数据的准备功能中显示错误。我已经控制了连接检查器。我不知道我的代码有什么问题。

这是我的代码:

 @IBAction func cancelButton(_ sender: Any) {
        performSegue(withIdentifier: "backToFirstScreen", sender: self)
    }


 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let tableViewVC = segue.destination as! tableViewController

        tableViewVC.passwordNotes3 = passwordNotes2
        tableViewVC.passwordCategory3 = passwordCategory2
        tableViewVC.passwordStrings3 = passwordStrings2

    }

1 个答案:

答案 0 :(得分:1)

我认为这里的问题是您尚未创建一个“ backToFirstScreen”序列,该序列始于第二个视图控制器,结束于第一个视图控制器。

使用搜索返回第一个屏幕有点禁忌;我将替换

performSegue(withIdentifier: "backToFirstScreen", sender: self)

使用

self.dismiss(animated: true, completion: nil)

或者如果您使用的是导航控制器

self.navigationController?.popViewController(animated: true)

这使您可以消除当前正在查看的ViewController并返回显示它的View Controller,而不必创建反向的Segue。只需确保您有一个顺序依次从第一个视图控制器到第二个视图控制器的。