我正在尝试使用“使用Swift进行App开发”(来自iBooks)这本书构建一个ElementQuiz应用程序。当我运行应用程序时,它会崩溃并转到AppDelegate页面,并显示一条绿色的行,上面写着“第1行:断点1.4”。
这是ViewController.swift:
// ViewController.swift
// ElementQuiz
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateElement()
}
@IBOutlet weak var image view: UIImageView!
@IBOutlet weak var answerLabel: UILabel!
@IBAction func showAnswer(_sender: Any) {
answerLabel.text = elementList[currentElementIndex]
}
@IBAction func gotoNextElement(_sender: Any) {
currentElementIndex += 1
if currentElementIndex >= elementList.count {
currentElementIndex = 0
}
updateElement()
}
let elementList = ["Carbon", "Gold", "Chlorine", "Sodium"]
var currentElementIndex = 0
func updateElement() {
answerLabel.text = "?"
let elementName = elementList[currentElementIndex]
let image = UIImage(named: elementName)
imageView.image = image
}
}
这是AppDelegate.swift:
//AppDelegate.swift
//ElementQuiz
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// This is the line with the "signal SIGABRT" error.
var window: UIWindow?
func application(_application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Override point for customization after application launch.
return true
}
}
那是我的代码。