0

When I press a specific button (Who's Next) it crashes the app. Though when pressing the other buttons those appears to work as expected. I have created all buttons with the same "method", and a lot of the functions are the same.

I have tried removing the buttons and the reference in the code, adding it again. I have also tried to remove the animation to see if that was the issue.

    import UIKit

    class ViewController: UIViewController {

    // IBOutlets for the different elements on the Main.storyboard.
        @IBOutlet weak var helperText: UILabel!

        @IBOutlet weak var questionText: UITextView!

        @IBOutlet weak var dreamButton: UIButton!

        @IBOutlet weak var reflectButton: UIButton!


        @IBOutlet weak var whosNextButton: UIButton!


// Question pool in an array about the dream questions.

    var dreamData = [
        "What is the most important thing you want to have accomplished within the next five years?",
        "2 dream",
        "3 dream",
        "4 dream",
        "5 dream",
        "6 dream",
        "7 dream",
        "8 dream",
        "9 dream",
        "10 dream",
    ]

// Question pool in an array about reflection questons.

    var reflectionData = [
        "What was the greatest achievement you accomplished the past five years?",
        "2 reflection",
        "3 reflection",
        "4 reflection",
        "5 reflection",
        "6 reflection",
        "7 reflection",
        "8 reflection",
        "9 reflection",
        "10 reflection",
    ]


// Name Pool for the Who's Next Button/function

    var namePoolData = [
        "Mathias",
        "Kasper",
        "Jason",
        "Oliver",
        "Jacob",
        "Mie",
        "Jenni",
        "Angela",
        "Mille",
        "Valerija"

    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        dreamButton.layer.cornerRadius = 15
        reflectButton.layer.cornerRadius = 15
        whosNextButton.layer.cornerRadius = 15
    }


//IBActions - Buttons on the Main.storyboard (Dream, Reflect, Who's Next?)


    @IBAction func dreamButton(_ sender: UIButton) {
        self.questionText.text = self.dreamData.randomElement()
        self.helperText.text = "Question about dreams!"
        UIButton.animate(withDuration: 0.2,
                         animations: {
                            sender.transform = CGAffineTransform(scaleX: 0.975, y: 0.96)
        },
                         completion: { finish in
                            UIButton.animate(withDuration: 0.2, animations: {
                                sender.transform = CGAffineTransform.identity
                            })
        })
    }


    @IBAction func reflectButton(_ sender: UIButton) {

        self.questionText.text = self.reflectionData.randomElement()
        self.helperText.text = "Question about reflections!"
        UIButton.animate(withDuration: 0.2,
                         animations: {
                            sender.transform = CGAffineTransform(scaleX: 0.975, y: 0.96)
        },
                         completion: { finish in
                            UIButton.animate(withDuration: 0.2, animations: {
                                sender.transform = CGAffineTransform.identity
                            })
        })
    }


    @IBAction func whosNextButton(_ sender: UIButton) {
        self.questionText.text = self.namePoolData.randomElement()
        self.helperText.text = "It is your turn!"
        UIButton.animate(withDuration: 0.2,
                         animations: {
                            sender.transform = CGAffineTransform(scaleX: 0.975, y: 0.96)
        },
                         completion: { finish in
                            UIButton.animate(withDuration: 0.2, animations: {
                                sender.transform = CGAffineTransform.identity
                            })
        })
    }


}

I expect the buttons to work the same as the other ones with minor adjustments to the outcome. So when I press the "Who's Next" button it should change the questionText and the helperText

Mantu
  • 1,017
  • 1
  • 10
  • 21
  • Error code: 2019-06-20 08:09:28.093701+0200 Shamaz[1646:71250] -[Shamaz.ViewController WhosNext:]: unrecognized selector sent to instance 0x7ff1bff045a0 2019-06-20 08:09:28.098831+0200 Shamaz[1646:71250] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Shamaz.ViewController WhosNext:]: unrecognized selector sent to instance 0x7ff1bff045a0' – Mathias Sørensen Jun 20 '19 at 06:52
  • it is clearly shown from the error that your outlets are not connected properly. – Mantu Jun 20 '19 at 06:55
  • Please make sure your button outlet is connected from your UI source. – Vikas Rajput Jun 20 '19 at 06:57
  • I'll try to connect the outlet to the UI source. Thanks. :) – Mathias Sørensen Jun 20 '19 at 07:23
  • The issue is now fixed.. Thanks a lot! – Mathias Sørensen Jun 20 '19 at 07:34
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – atalayasa Jun 20 '19 at 08:47

0 Answers0