1

I've read that it's possible to connect a UIControl's action to an existing function in a ViewController by ctrl-click-dragging to that existing method.

What I'm expecting it to do is highlight the existing function and then setup the connection to it. However, I've tried a number of times and it doesn't appear to work. It always wants to insert a new one (see screenshot)

Missed Connections

I'm using Swift (as you can see) along with Xcode 6.1.1.

Has anybody else experienced this? Could this be a bug with this version of Xcode?

Update: To show that even dragging on the name doesn't help :-(

Missed Connections Two

Jeffrey Harrington
  • 1,797
  • 1
  • 15
  • 24
  • Works fine for me. Idea: try dragging the other way, from the circle at the left of line 21 to the button. – matt Dec 11 '14 at 02:24
  • Another idea: what was the last time you quit Xcode? It does sometimes need a slap in the head. Quit and restart can fix a lot of stuff. – matt Dec 11 '14 at 02:25
  • Does the class of the viewController in the storyboard match the class of the file? – Matthias Bauch Dec 11 '14 at 08:34
  • The screenshot above is taken from a fresh project with the Main.storyboard and ViewController.swift. So it should be the correct class. – Jeffrey Harrington Dec 11 '14 at 18:34
  • I tried dragging the opposite way (from circle to button) and I still can't connect it. I've even tried the tip in the comment below of dragging directly to the name. Very weird! – Jeffrey Harrington Dec 11 '14 at 18:35
  • Did you restart, as I suggested? Did you recompile the project? Did you try quitting, cleaning out the cache, and then restarting and recompiling? The goal here is to re-index the project. When I say "clean the cache" I am referring to my instructions here: http://stackoverflow.com/questions/5714372/how-to-empty-caches-and-clean-all-targets-xcode-4/6247073#6247073 – matt Dec 11 '14 at 18:52
  • 1
    Also, if restarting doesn't help, please try this with another (clean new) project, since there is just a chance that your project is corrupted somehow. I am grasping at straws here, because it is hard to see why it would offer to insert the outlet-or-action but _not_ the connection to the existing function. It's almost as if it doesn't _see_ the existing function - that is why I say you need to compile at the very least. – matt Dec 11 '14 at 18:53
  • Are you sure your button is actually a UIButton? What does the function you insert look like when you let it insert a new action? – shim Dec 11 '14 at 19:04
  • Restarted XCode, restarted my machine, and even started with a fresh new project. I can't seem to get this to work! That's why I initially wondered if it was a bug with Xcode. Is there a way for me to reset my Xcode config settings? – Jeffrey Harrington Dec 11 '14 at 21:29
  • It's not a "config" thing. I'm using Xcode 6.1.1 too so I can't explain the difference in our experiences, sorry... :( You did the cache-cleaning stuff I pointed you to? – matt Dec 11 '14 at 22:15

6 Answers6

2

After downgrading to Xcode 6.1, the issue was resolved.

I can now connect controls to existing IBActions on a ViewController

enter image description here

Very strange.

Jeffrey Harrington
  • 1,797
  • 1
  • 15
  • 24
1

It should work. I'm going to suggest that your project's index is wedged and that cleaning the cache to force reindexing will solve the problem.

Here is a picture of me performing the desired gesture (I tried to set things up as close as I could to your screen shot):

enter image description here

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 2
    As shown above, the key is to actually drag onto the name of the function. Works for outlets too, as long as you drag onto the name of the outlet. In fact I had to do it this way as xcode was refusing to create a new outlet. – jpmcc Dec 11 '14 at 14:00
  • Thanks, I tried to drag directly onto the name of the function and it still doesn't seem to work. I've even changed the function signature to not have a 'sender' parameter with no luck :-/ – Jeffrey Harrington Dec 11 '14 at 18:38
0

I'm also facing this issue just like yours. It's very strange that it will work after I update xcode each time. And it won't work after I reopen xcode or restart my computer. This makes me believe that it's not a bug or any application problem.

After lots of experiments, I found out a strange way to fix this issue. Go to the systems preference and settings. And go to the language and region. Then change your language and region. It will ask you to restart then restart your mac. It should work at least for that time.(I'm quite confident that only restart your computer won't help...)

Teng Long
  • 435
  • 6
  • 14
0

I found the same problem. This problem is caused by the path.

  1. check the paths of the storyboard and swift files.Location is the same(relative to group),but the paths are different,one is "",another is "../../../"

  2. if paths are different, you can't do the connect action

    it does not work


  1. make sure paths are the same. open and edit the xcodeproj file.

PATH_TO_YOUR_PROJECT/PROJECT_NAME.xcodeproj

replace the "../../../../../hill/project/iOS project/Checklists/Checklists/xxx.swift" to "xxx.swift"

  1. try it again

    it works

0

In Swift 3, we'd like to change the @IBAction's argument type from (_ sender: Any) to (_ sender: UIButton) or (_ sender: AnyObject).

However it should be done manually.

It might work well.

Lin
  • 497
  • 5
  • 15
-1

Had the same issue in xCode 7.0.1. I tried restarting xcode, confirming that the file paths were in the same group, clearing out the cache. In the end, restarting my computer fixed the problem. Simple, but frustrating after 2 hours of trying different things...

tylerSF
  • 1,479
  • 2
  • 16
  • 25