【发布时间】:2018-08-22 09:54:27
【问题描述】:
我是 Swift 新手,我正在尝试开发一个测验应用程序。当我尝试在我的 iPhone 上加载应用程序时,我在 AppDelegate 类中收到 SIGABRT 错误,然后手机上只有一个白屏。我怎样才能解决这个问题?我已经尝试清理代码,我删除并仔细检查了按钮和代码之间的链接(如另一个问题与这些答案所建议的那样),我仍然收到此错误。
下面是我的视图类
import UIKit
import Foundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateQuestion()
}
//Label
@IBOutlet weak var label: UILabel!
@IBOutlet weak var scorelabel: UILabel!
@IBOutlet weak var flagview: UIImageView!
//Botones
@IBOutlet var botona: UIButton!
@IBOutlet var botonb: UIButton!
@IBOutlet var botonc: UIButton!
@IBOutlet var botond: UIButton!
let allQuestions = QuestionBank()
var questionNumber: Int = 0
var score: Int = 0
var selectedAnswer: Int = 0
//Button
@IBAction func boton(_ sender: UIButton) {
if sender.tag == selectedAnswer {
print("Correcto")
score+=1
}
else {
print("Incorrecto")
}
updateQuestion()
}
func updateQuestion(){
flagview.image=UIImage(named:allQuestions.list[questionNumber].questionImage)
label.text=allQuestions.list[questionNumber].question
botona.setTitle(allQuestions.list[questionNumber].optionA, for: UIControlState.normal)
botonb.setTitle(allQuestions.list[questionNumber].optionB, for: UIControlState.normal)
botonc.setTitle(allQuestions.list[questionNumber].optionC, for: UIControlState.normal)
botond.setTitle(allQuestions.list[questionNumber].optionD, for: UIControlState.normal)
selectedAnswer = allQuestions.list[questionNumber].correctAnswer
questionNumber += 1
}
func updateUI(){
}
func restartQuiz(){
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
任何帮助都将不胜感激!先感谢您。
【问题讨论】:
-
您很可能断开了
IBOulet之间的连接。您是否重命名了插座,而不是删除旧链接并重新连接? -
我确实重命名了一个按钮,如何跟踪当前和旧链接?