我正在尝试使用“App Development with Swift”(来自 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
}
}
那是我的代码。
最佳答案
关于swift - ElementQuiz 应用程序-线程 1 : breakpoint 1. 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44459528/