我正在尝试制作一个会问问题的应用,而您必须回答是非题。这是我正在参加的在线课程的一部分。我首先面对的挑战是在屏幕上显示“ 4 + 2等于6”并显示它。这是我为显示该代码而编写的代码。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var optionBar: UIProgressView!
@IBOutlet weak var trueButton: UIButton!
@IBOutlet weak var falseButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
questionLabel.text = "Four + two is equal to 6"
}
@IBAction func answerButtonPressed(_ sender: UIButton) {
}
}
当我尝试运行模拟器时,出现错误:
以NSException类型的未捕获异常终止
它将我带到我的appDelegate屏幕并显示错误:
异常:“ [
第3行。代码如下:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
你们中有人知道如何解决此问题吗?