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

后端 未结 5 1439
感情败类
感情败类 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 20:47

    What fixed this for me (and it gets me everytime, especially when you are new to using storyboards) is to make sure that you are initializing your view controller like so :

    slideShowVC = (UIStoryboard(name: "Main",bundle: nil).instantiateViewControllerWithIdentifier("WWPhotoSlideShowVC") as! WWPhotoSlideShowVC)
    

    instead of the stand alone xib way :

    slideShowVC = WWSlideShowVC()
    

    Or else all your outlets will be nil na many headaches will soon follow.

提交回复
热议问题