Swift: label text --> “fatal error: unexpectedly found nil while unwrapping an Optional value”

后端 未结 5 1588
感情败类
感情败类 2021-01-17 20:10

like it says in the title, i am trying to change label text upon click of a button. Error appears at line self.playerChoice.text = \"You: Rock\"



        
5条回答
  •  佛祖请我去吃肉
    2021-01-17 21:12

    Looks like player choice is not initialized.

    @IBOutlet var playerChoice: UILabel!
    

    Maybe the connection between the outlet and InterfaceBuilder/Storyboard is lost. Try to connect it again.

    I've created a small demo and everything works fine:

    enter image description here

    Check if the circles at the left side of your IBOutlet are filled. Otherwise the connection is lost.

提交回复
热议问题