按钮文字-调试错误帮助-Swift

时间:2019-06-26 21:46:29

标签: debugging uiviewcontroller

我是Swift和编码的新手,正在寻求帮助,这是我尝试独立开发的第一个应用程序。

我在更新按钮文字时遇到问题。

我的代码如下:

代码:

import UIKit

class ViewController: UIViewController {

    // Our strings
    let story1 = "Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: \"Need a ride, boy?\"."
    let answer1a = "I\'ll hop in. Thanks for the help!"
    let answer1b = "Better ask him if he\'s a murderer first."


    let story2 = "He nods slowly, unphased by the question."
    let answer2a = "At least he\'s honest. I\'ll climb in."
    let answer2b = "Wait, I know how to change a tire."

    let story3 = "As you begin to drive, the stranger starts talking about his relationship with his mother. He gets angrier and angrier by the minute. He asks you to open the glovebox. Inside you find a bloody knife, two severed fingers, and a cassette tape of Elton John. He reaches for the glove box."
    let answer3a = "I love Elton John! Hand him the cassette tape."
    let answer3b = "It\'s him or me! You take the knife and stab him."

    let story4 = "What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?"
    let story5 = "As you smash through the guardrail and careen towards the jagged rocks below you reflect on the dubious wisdom of stabbing someone while they are driving a car you are in."
    let story6 = "You bond with the murderer while crooning verses of \"Can you feel the love tonight\". He drops you off at the next town. Before you go he asks you if you know any good places to dump bodies. You reply: \"Try the pier.\""

    // UI Elements linked to the storyboard
    @IBOutlet weak
    var topButton: UIButton! // Has TAG = 1
    @IBOutlet weak
    var bottomButton: UIButton! // Has TAG = 2
    @IBOutlet weak
    var storyTextView: UILabel!


        // TODO Step 5: Initialise instance variables here


        override func viewDidLoad() {
            super.viewDidLoad()


            // TODO Step 3: Set the text for the storyTextView, topButton, bottomButton, and to T1_Story, T1_Ans1, and T1_Ans2

            storyTextView.text = story1

            topButton.setTitle(answer1a,for: .normal)

            bottomButton.setTitle(answer1b,for: .normal)

        }


    // User presses one of the buttons
    func buttonPressed(_ sender: UIButton) {

        // TODO Step 4: Write an IF-Statement to update the views

        // TODO Step 6: Modify the IF-Statement to complete the story

        if sender.tag == 1 {

            storyTextView.text = story3

            topButton.setTitle(answer3a,for: .normal)

            bottomButton.setTitle(answer3b,for: .normal)

        }

        else if sender.tag == 2 {

            storyTextView.text = story2

            topButton.setTitle(answer2a,for: .normal)

            bottomButton.setTitle(answer2b,for: .normal)
        }
    }
}

因此,该应用程序的构建绝对正常,并且在我尝试按下顶部或底部按钮之前不会出现任何问题。

然后崩溃,并在调试控制台中说它指出“发送到实例的无法识别的选择器”。

在委托中还说线程1 SIGABRT

0 个答案:

没有答案
相关问题