Jeffrey Harrington
Jeffrey Harrington

Reputation: 1797

Cannot connect action to existing function in Xcode 6.1.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

Upvotes: 1

Views: 2731

Answers (6)

Lin
Lin

Reputation: 507

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.

Upvotes: 0

tylerSF
tylerSF

Reputation: 1539

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...

Upvotes: -1

hillchan31
hillchan31

Reputation: 1

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

Upvotes: 0

Teng Long
Teng Long

Reputation: 455

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...)

Upvotes: 0

Jeffrey Harrington
Jeffrey Harrington

Reputation: 1797

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.

Upvotes: 2

matt
matt

Reputation: 535880

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

Upvotes: 1

Related Questions