Can't connect outlets in IB

I'm using a storyboard for a project I've been working on for sometime. A couple of days ago I added a new label to a view controller, tried to connect it to outlet and wasn't able to (by wasn't able to I mean I right clicked on the label, clicked on New Referencing Outlet, and dragged the connector to the orange view controller icon. Instead of it highlighting and popping up a list of available outlets nothing happened). I tried different interface items with the same result then I deleted a current connection and tried to reconnect it and it failed too (luckily Undo restored it). In addtion I discovered I couldn't connect actions and existing connected actions now have a caution sign that, when moused over, says "<the interface object> is no longer a valid event source". Luckily the app continues to compile and run. Eventually I found if I delete the view controllers corresponding source and add it back everything returns to normal.


Has anyone else had similar issues and if so is there another fix? I'm using Xcode 8.3.2 on macOS 10.12.2


Short observation about Xcode. I'm primarily an iOS developer but I do some Android development. When I first started using Android Studio I hated it. It's ugly, cluttered and obviously wasn't designed by someone that understood good interface design - nothing like the sleek, sophisticated interface design of Xcode - but it works. It works really well. It doesn't hang, it doesn't crash, stuff that's worked for years doesn't suddenly break. Things like refactoring and finding usages of variables and objects are light years ahead of Xcode. With WWDC right around the corner we can expect a new version of Xcode with a slew of new features and a slew of new bugs and issues. What I wish they'd do is make the current version stable and functional. Forget new features just fix what's already there.

Replies

Did you try to clean build folder from Product menu (option-clean the project) ?

I tried cleaning the project and restarting Xcode.

OK. I met this trouble before (outlets and actions can't be connected to the code). Please check the Assistant editor. Is it Manual or Automatic? Set it to Automatic if it's Manual.

Interesting.


Where do you set the mode for assistant editor ?

In the jump bar at top of the assistant editor pane. One of the things that automatic mode does, and to which Joshua will be referring: clicking on a UI element in IB results in the assistant editor automatically displaying the source code for the UIViewController subclass that has been specified for the view controller which contains the element, which facilitates control-dragging an IBAction or IBOutlet connection.

It says "Manual" now but there doesn't seem to be an option to switch to "Automatic"


You should have Automatic available when a storyboard is open in main editor pane. Do you have a storyboard visible?


I very much doubt that your problem will be solved by switching assistant editor to automatic, anyway. (Joshua's problem would have been he had the source code for the wrong VC opened in assistant editor when in manual mode, and automatic mode made sure the correct VC was open when he control-dragged connections from storyboard elements to the source code.)

Maybe this lot is related to your problem, and if so then see my suggestion in the thread of the first link, except substitute UIView for UIControl in the case of a label:


https://forums.developer.apple.com/thread/25180

h ttps://github.com/lionheart/openradar-mirror/issues/16711

h ttp://stackoverflow.com/questions/36361687/xcode-7-3-uitextfield-is-no-longer-a-valid-event-source

In Xcode 8.3.3 I see the method for linking has been inverted. Now instead of dragging from the IB object to the code, I drag from the line of code to the object. It seems a lot easier and requires fewer clicks.


Hope this helps.

Both ways should work : from IB to code of from code to IB.


However, I have noted it may happen that only one works (until you option-cleaned or even reopened the file).

Hi,


I'm sure that since then you surely have found the root cause of the problem but...

in case, other guys like like found this thread while encountering same issue and are using XCode 10, the root cause of not being able to embed an outlet from a textfield into its viewcontroller was that my viewController in the storyboard didn't had as its CustomClass property set to the class I created to handle actions and outlets.


Regards

Olivier.

Found way.


first, delete the viewcontroller and create new one, then assign the new one to the storyboard that you want to make outlet.


This will work.


(Editting viewcontroller's title in script or file can provoke this problem)

One more thing (for code copy-and-pasters): Ensure that the type declared in the code for the outlet or action matches the type of the object in the storyboard 😐