-3

I'm new to Xcode and was trying to make a simple code that would unhide a label when a button is pressed. I tried using the same code in a test project with one view controller and it worked just fine, but when I use it in a bigger project with 15+ view controllers I get the error. My outlets seem to be correct so I am not sure what is making the label nil.

Code that I used

Fixed it! Just manually initialized the object as hidden under drawing.

  • https://stackoverflow.com/questions/29321383/iboutlet-is-nil-but-it-is-connected-in-storyboard-swift – Dilan Apr 08 '20 at 01:45

1 Answers1

0

This error seem to be caused by the Outlet connecting problem to me, I would suggest you to double check the storyboard & viewController connection.

To do so, you can go to your storyboard, and check on the all outlet connector in that scene.

If there are yellow sign, that mean that are the problems.

enter image description here

But if the outlet are correctly connect, try to move that line of code to ViewWillAppear, and see if the error still occurs.

pu_sam
  • 11
  • 2
  • I checked the outlets again, they seem to be fine. It still didn't work. Then I moved the line to viewWillAppear and it's still returning nil. – mushmonster Apr 08 '20 at 13:25
  • I also just noticed that the error only comes up when initializing and not when called through the button. – mushmonster Apr 08 '20 at 13:30