[英]SIGABRT error in swift after a button is pressed - the segue doesn't execute
I'm trying to make a leaderboard for a word scrambler app so I am saving the data before segueing to the next view controller which will eventually be a leaderboard.我正在尝试为 word scrambler 应用程序制作排行榜,因此我在转到下一个最终将成为排行榜的视图控制器之前保存数据。 My outlets are all connected and the segue identifier was written correctly so I don't see why the app crashes after done is pressed我的插座都已连接并且 segue 标识符写正确,所以我不明白为什么按下完成后应用程序崩溃
the error line occurs here: class AppDelegate: UIResponder, UIApplicationDelegate {错误行出现在这里: class AppDelegate: UIResponder, UIApplicationDelegate {
var finalScore = Int()
var playerName = String()
var allMyStoredData = UserDefaults.standard
class secondVC: UIViewController {
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var nameTF: UITextField!
@IBOutlet weak var doneButton: UIButton!
var playerScore = 0
override func viewDidLoad() {
super.viewDidLoad()
scoreLabel.text = "Your score is: \(finalScore)"
loadData()
}
@IBAction func donePressed(_ sender: Any) {
saveData()
//this part won't execute
performSegue(withIdentifier: "toLeaderboard", sender: self)
}
func saveData () {
playerName = nameTF.text!
playerScore = finalScore
allMyStoredData.set(playerName, forKey: "saveTheName")
allMyStoredData.set(playerScore, forKey: "saveTheScore")
}
func loadData () {
if let loadPlayerName:String = UserDefaults.standard.value(forKey: "saveTheName") as? String {
playerName = loadPlayerName
}
if let loadTheScore:Int = UserDefaults.standard.value(forKey: "saveTheName") as? Int {
playerScore = loadTheScore
}
}
}
更新:视图控制器中有一个出口,segue“toLeaderboard”没有连接或使用,所以我删除了它,现在代码很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.