iOS - 线程1:信号SIGABRT错误

时间:2017-05-15 14:23:38

标签: ios

我想制作一个简单的游戏,玩家可以在这个ViewController中调整一些值。但是当我触摸save按钮时,此应用程序始终会关闭。我不知道如何解决这个问题。

代码:

class QMOptionViewController: UIViewController {

@IBOutlet weak var TimeLabel: UILabel!
@IBOutlet weak var ScoreLabel: UILabel!
var ScoretoWin = Int(10)
var Time = Int(60)

override func viewDidLoad() {
    super.viewDidLoad()
    TimeLabel.text = "\(Time)"
    ScoreLabel.text = "\(ScoretoWin)"

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

@IBAction func TimeStepper(_ sender: UIStepper) {
    let stepperval = sender.value
    Time = Int(stepperval)
    TimeLabel.text = "\(stepperval)"
}

@IBAction func ScoreStepper(_ sender: UIStepper) {
    let stepperval = sender.value
    ScoretoWin = Int(stepperval)
    ScoreLabel.text = "\(stepperval)"
}

@IBAction func SaveButton(_ sender: Any) {
    self.performSegue(withIdentifier: "Save", sender: self)
}

// 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.

    if segue.identifier == "Save" {
        let destination = segue.destination as! QMGameViewController
        destination.timeleft = Time
        destination.scoretowin = ScoretoWin
        UserDefaults.standard.set(time, forKey: "totaltime")
    }
  }   
}

错误:

error

行动:

button action

1 个答案:

答案 0 :(得分:0)

根据您提供给我们的信息,您应检查可能导致崩溃的两件事:

  1. 您的segue配置正确吗?意思是,你的segue是否有标识符" Name"设置并将segue从QMOptionViewController拖到QMGameViewController?如果不是,您的应用将尝试解决零属性并崩溃。
  2. 您是否将应该由QMGameViewController管理的场景连接到Storyboard中的此类。如果您忘记连接属于QMGameViewController的场景并且您明确地将目标转换为此类,则您的应用程序将崩溃,因为目标不是QMGameViewController。
  3. 顺便说一句,我不会使用segue目标视图控制器的名称destination,而是使用destinationVC或更明确的destinationQMGameVC。

    我希望这能解决你的问题。否则我需要更多信息。

    亲切的问候, MacUserT