Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect IBOutlet from storyboard to UIView subclass

I am able to right-click and drag from my custom UIView subclass file to the storyboard elements to connect them, but unable to do so the other way around. I believe this is an Xcode bug. Is there anything that I can do to fix this? This is not the first time that it happen already and its annoying.

I already tried cleaning and restarting Xcode several times with no luck.

This does not work This does not work (Right clicking from the storyboard to Swift file)

This works This works (Right clicking from swift file's IBAction to storyboard)

Btw, I am using Xcode 8.1 with Swift 3.0.

UPDATE: I'm not looking for an answer on how to connect IBOutlets/IBActions, because as I mentioned in question above (and also in the screenshots), I am already able to connect them and the app is running fine. The question is more on WHY Xcode wouldn't let me connect from Storyboard > Swift file, but letting me to do so from Swift file > Storyboard. I'm sorry if the question is misleading.

like image 757
Chan Jing Hong Avatar asked Dec 02 '16 12:12

Chan Jing Hong


3 Answers

We see this issue sometimes too since Xcode 8, and assume this is a Xcode bug.

As a workaround:

  • Write the outlet in code @IBOutlet weak var myUiElement: UIView!

  • Ctrl + Drag from your outlet to the UI element in the Storyboard

like image 157
shallowThought Avatar answered Nov 15 '22 12:11

shallowThought


Its basic, but easy to overlook. Make sure the view controller you are dragging the outlet to is labeled as the custom class you created.

enter image description here

like image 24
ScottyBlades Avatar answered Nov 15 '22 11:11

ScottyBlades


After trying some of the given solution what finally worked is by restarting the my macbook. It seems like a bug on XCode's side. Oh well.

like image 7
Chan Jing Hong Avatar answered Nov 15 '22 10:11

Chan Jing Hong