Unable to use cmd+drag to make storyboard segues with custom UIControl.

Hi guys,
I cannot get a custom UIControl to allow me to use command+drag to create a segue in the storyboard. I know they can be done programatically but I need to do them in the storyboard per requirements and was wondering if there's a trick to add this functionality.
When I try with a custom UIControl, the connection from my control to the other view controller never "attaches" and no blue square around the other view controller and menu popoup for a segue appears. I've tried adding a gesture recognizer and ensuing sendTo events were active but no dice. I also tried dragging from the heirarchy view but again nothing. It's like the control doesn't even see the second view controller.
For troubleshooting I even tried making a completely empty project, empty class that inherits from UIButton (which should already have those things) and it still doesn't work. (And yes, my view is set to the Custom UIButton in the storyboard.)
I did notice that with the controls that do work they all have a "Triggered Segues" section in the connections inspector and wonder if that may be the key.
I'm on XCode 10.3.

Replies

Did you declare it IBDesignable ? And possibly, its properties IBInspectable, such per this example:


@IBDesignable
class CheckBox: UIButton {
   
    @IBInspectable public var isChecked: Bool = false

Just tested (XCode 10.2) with a subclassed UIButton.

- I declared the button in IB as belonging to the subclass

- I could connect to IBOutlet or IBAction in the subclass code

- I could control drag from the button to another VC to define a segue

I tried again thinking maybe it was just my work computer but nope, still at home no dice:

This is literally the only code in the test class (just an overridden UIButton): https://imgur.com/a/KUXljvz
Here's me showing that the control is associated with the correct class: https://imgur.com/a/vunkuKl
Video of me trying to connect it via the storyboard: https://gfycat.com/jubilantwavydartfrog
The other view controller also has a test class associated with it. I tried making the class designable like you suggested but it didn't work either.
I'm on Xcode 10.3 at home and at work.

I tested your exact setup and it works.

No IBDesignable needed in fact.


Could you try to connect the TestButton to an IBOutlet in the code ?

Yep. It connects to outlets and actions just fine, it just doesn't work with segues. I'm wondering if its an Xcode 10.3 bug because I swear I've done this just fine a million times before.

Just tested on XCode 10.3, I did succeed to create the segue.

And it works well in simulator.


You speak of cmd-drag. Do you mean control-drag (cmd-drag willl not work for this).

I also noticied in Identity inspector for the button, that Traits Button is not activated. That does not seem to change (I succeed creating segue without), but in case.


Maybe you should reinstall XCode Otherwise.

Yes I meant control drag. It can't imagine it being my Xcode install, this is happening on my home machines, and the three work machines I tried it on. I honestly have no clue how you're getting it to work because not I or any of my coworkers are able to get it working either.
Something is screwy here. I'll try and post a full video of exactly how I made the project when I get home, maybe it's something stupid we're all missing.

Of course, you did an option-clean Build Folder ?


Or maybe you could temporarily post an email address so that we can share files.

Did you post a video ? Or maybe you solved the problem ?

Probably an odd behavior, but just dropping it here because of having the same Issue and probably someone in the future might need it.

The only thing I could observe was that when I dragged into the "storyboard canvas" an UIView and changed it to the UIButton-Subclass, the Ctrl-Drag behavior was as if it was an UIView.

However, if I dragged into the "storyboard canvas" an UIButton and then changed it to the UIButton-Subclass, the Ctrl-Drag behavior was like that of a UIButton.

the Ctrl-Drag behavior

What do you exactly mean by that ?

When I define an action to the UIView declared as UIButton in IB, I get the same list of possible events.