简体   繁体   中英

How to fix “ fatal error: unexpectedly found nil while unwrapping an Optional value ” outlet button

When I try to do Play.hidden = true , I get the error message "fatal error: unexpectedly found nil while unwrapping an Optional value". My button outlets are connected.

连接插座

Here's my code(inside of viewController class) :

 @IBOutlet weak var Play: UIButton!
@IBOutlet weak var Stop: UIButton!

Here's my method:

 @IBAction func recordButton(sender: AnyObject) {
   Play.hidden = true

}

Here's another screenshot:

屏幕截图xcode Any suggestions would help. Thank you!

Thanks guys for all your suggestions . I just disconnected the play button outlet and connected it again(Credit to @HAS).[I also renamed the Outlet from "Play" to "playButton" because I have a variable var play = AVAudioPlayer() .

I'm not sure what the reason was but it is now fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM