我百分之百的确信所有的东西都连接好了,但我还是不断地得到一个sigabret错误。
以下是SelectViewController的代码:

import UIKit

class SelectViewController: UIViewController {

var accounttype = 0

@IBAction func AdminButton(_ sender: Any) {
}

@IBAction func ParentButton(_ sender: Any) {
}

@IBAction func DriverButton(_ sender: Any) {
}

@IBAction func StudentButton(_ sender: Any) {
    accounttype = 1
}



override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    var SubmitController = segue.destination as! SubmitViewController
    SubmitController.john = accounttype;

}


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

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


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

以下是SubmitViewController的代码:
import UIKit

class SelectViewController: UIViewController {

var accountType = 0

@IBAction func AdminButton(_ sender: Any) {
}

@IBAction func ParentButton(_ sender: Any) {
}

@IBAction func DriverButton(_ sender: Any) {
}

@IBAction func StudentButton(_ sender: Any) {
    accountType = 1
}



override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let destination = segue.destination as? SubmitViewController {
        destination.john = accountType
        print("Inside if statement")
    }

}


override func viewDidLoad() {
    super.viewDidLoad()

     print("Out of if statement")
    // Do any additional setup after loading the view.
}

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


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

这是控制台:
2018-08-28 17:17:56.529276-0700 SchoolDrive[5178:1005170] 5.4.1 - [Firebase/Analytics][I-ACS023007] Firebase Analytics v.50001000 started
2018-08-28 17:17:56.529921-0700 SchoolDrive[5178:1005170] 5.4.1 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2018-08-28 17:17:57.024884-0700 SchoolDrive[5178:1005198] TIC Read Status [1:0x0]: 1:57
2018-08-28 17:17:57.025067-0700 SchoolDrive[5178:1005198] TIC Read Status [1:0x0]: 1:57
2018-08-28 17:18:01.737912-0700 SchoolDrive[5178:1005175] TIC Read Status [2:0x0]: 1:57
2018-08-28 17:18:01.738363-0700 SchoolDrive[5178:1005175] TIC Read Status [2:0x0]: 1:57
2018-08-28 17:18:03.755460-0700 SchoolDrive[5178:1005196] TIC Read Status [3:0x0]: 1:57
2018-08-28 17:18:03.755664-0700 SchoolDrive[5178:1005196] TIC Read Status [3:0x0]: 1:57
Could not cast value of type 'SchoolDrive.SecondRegisterViewController' (0x10d8349d0) to 'SchoolDrive.SubmitViewController' (0x10d834820).
2018-08-28 17:18:04.613651-0700 SchoolDrive[5178:1004484] Could not cast value of type 'SchoolDrive.SecondRegisterViewController' (0x10d8349d0) to 'SchoolDrive.SubmitViewController' (0x10d834820).
(lldb)

我非常感谢大家的帮助,感谢大家的帮助。提前谢谢你。我需要尽可能快的帮助。这会让我更容易。再次感谢你的帮助,我非常感激。

最佳答案

在您的情况下,它会崩溃,因为要修复的强制转换使用if letguard来防止崩溃。将prepare(for:, sender:)方法中的代码修改为下面的。

if let destination = segue.destination as? SubmitViewController {
  destination.john = accountType
}


guard let destination = segue.destination as? SubmitViewController else {
  return
}

destination.john = accountType

关于ios - 由于SIGABRT,应用程式当机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52067824/

10-09 18:32