23

I have created a custom cell for loading into a table. The interface is complete and now I am trying to link the xib and the class.

I have the split screen view open and I try to control drag the item so that Xcode can make the connection for me. When I fill in the name and click connect I get an error:

Could not insert new outlet connection: Could not insert source code into document at URL://localhost/Users/Velox/Projects/CompanyName/ProjectName/ProjectName/HistoryCell.m because it does not contain a class definition for the class named HistoryCell.

I have set the custom class of the xib to HistoryCell.

What am I missing here?

Thanks.

Daniyar
  • 2,975
  • 2
  • 26
  • 39
Dale Myers
  • 2,703
  • 3
  • 26
  • 48
  • 1
    try to connect it programatically by setting your iboutet in .h file. – iOS Developer Jun 12 '12 at 11:58
  • possible duplicate of [Xcode 4: Creating a UIView xib, not properly connecting](http://stackoverflow.com/questions/6703054/xcode-4-creating-a-uiview-xib-not-properly-connecting) – Max MacLeod May 22 '15 at 14:33

21 Answers21

75

This problem seems to be an Xcode bug which creeps up mostly when you replace a file with a new file of the same name. Xcode seems to keep a reference of the older file of the same name.

Anyhow, the way to fix this seems to be -

  1. Clean the project

  2. Click <Your Project> in Project Navigator view. Go to Compile Sources under Build Phases of the target for which you are building. Remove and add back the .m file which is giving you trouble.

  3. Alternatively, in the File Inspector (Utilities view) of the NIB file, under Target Membership, uncheck and check back the target name.

  4. Restart Xcode for good measure.

  5. Of course, deleting and adding back the .m file alone should fix it too.

Steps 1. and 2. alone fixed it for me. Feel free to ask if any step needs expanding.

Cheers and happy coding :)

codeburn
  • 1,994
  • 17
  • 20
20

I fixed this issue by deleting the .m file (reference only) then adding it back in to the project. I think XCode gets corrupted at times (and I'm on the latest 4.6).

Daniel Ryan
  • 6,976
  • 5
  • 45
  • 62
5

https://stackoverflow.com/a/16166878/521946

Try to clean your project and restart Xcode.
If it still cannot be connected, follow the Utilities navigation view of Xcode, in the Target membership section, uncheck & check the checkbox, it will be work. Maybe you should rebuild the project after unchecking.

Community
  • 1
  • 1
Elf Sundae
  • 1,575
  • 16
  • 23
4

Quit XCode, then purge the derivedData using:

rm -rf ~/library/Developer/Xcode/DerivedData/*

Restart XCode and connect.

If you want, create an alias

alias purgeallbuilds='rm -rf ~/library/Developer/Xcode/DerivedData/*'

in your .bash_profile as suggested here.

Community
  • 1
  • 1
benaneesh
  • 426
  • 6
  • 10
4

Just go to .m file

remove

#import "calssName.h" 

save file

add text again

#import "calssName.h"

save file

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Fadi Abuzant
  • 476
  • 8
  • 13
3

So, it turns out that I was being a fool. You can't quite do it like this with Xcode. If you create the properties manually in the header file, then synthesise them in the class file, you can then link by doing the following:

Open the xib file Right click on the cell in the "Objects" panel Click and drag from the options here to the objects on the xib.

That's all there was to it.

Dale Myers
  • 2,703
  • 3
  • 26
  • 48
  • I have this issue too. How do I know when can I ctrl-drag the object to create outlet connections? I remember sometimes I can do that when I was developing master detail apps and for some single view apps. – newguy Jun 14 '12 at 01:18
  • @newguy I think it is ok as long as you aren't using a custom component. – Dale Myers Jun 14 '12 at 06:49
  • It is strange because I don't have any custom component. I just put some labels on the view controller and I don't even give a name or have a subclass of that view controller, which means the view controller has a default class name "ViewController". – newguy Jun 14 '12 at 07:30
  • Thanks! Just learned about `ctrl-drag` shortcut for outlet references. – vaughan Sep 29 '13 at 11:39
3

The problem could be caused by other errors. Build the program, if there are any errors or warnings, fix it. Then ctrl-drag to insert outlet again and the problem will go away.

Philip007
  • 3,190
  • 7
  • 46
  • 71
3

I had the same problem for a viewcontroller which was removed accidantly.I readded files to project but adding Outlets by draging with from xib file gave me the mentioned error.I cleaned the project and restarted XCode and everything worked fine again.

Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
2
  1. Remove .m file from compoile sources and add again.
  2. clean and build your project.
  3. Restart xcode.

In my case, #1 fixed the issue

benka
  • 4,732
  • 35
  • 47
  • 58
Abdul Rehman
  • 613
  • 6
  • 9
2

I had the same issue with Xcode 6.2 In this case it was sufficient to 'touch' the target class - by adding and removing something meaningless - to force a recompile. The issue went away then.

1

while the remove and add again solutions seemed to work a bit. I luckily had this same situation early on and wanted an easy way to fix it just incase it happened knee deep in programming. It turns out if you just build the the project "Command B" or go to Product and go to build. This worked fine and associated my view with the designated file.

1

I used xCode 7 and iOS 9.

in your .m

delete #import "VC.h"

save .m and link your outlet again it work fine.

Ahmed Abdallah
  • 2,338
  • 1
  • 19
  • 30
0

I had another window of Xcode opened up for another project and the simulator was also running. I just closed both of them and Product-> Clean my current application. It works.

nanospeck
  • 3,388
  • 3
  • 36
  • 45
0

For me restarting Xcode did not work, I just deleted the object and added again then started working.

Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75
0

It worked in my case. 1 create new project with different name 2 copy and paste file to it 3 delete file from first project 4 copy and paste file from new project to first project.

0

I tried "Product>Clean" and then "Product>Clean Build Folder" but still had problems. Then I simply deleted the offending .m and .h files associated with the view controller that was giving me problems, created a new .m and .h for the view controller class, reassigned the new view controller class to the storyboard object I was having troubles with, and everything worked.

Samuel W.
  • 370
  • 1
  • 10
0

I have the reported problem trying to add a new Watch target to an old project as I successfully did several times on blank projects following tutorials. I tried inserting the target an scheme and removing both the files, the targets and schemes, as well restarting Xcode and deleting the derived files many times. But each time I recreate the target and try to activate the Assistant Editor, it finds no correspondent file to the main storyboard, and if I manually select it and then try to drag a new outlet I get the error of the original poster. What else could it be? As a metter fo fact my error is quite different as you may see in the screenshot.enter image description here

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
  • Search for duplicated ClassNames or StoryBoardsIDs within your `.storyBoard` editing as XML, I found duplicated names due old bogus references @abhi1992. If you other trick worked for you please share it :) – Jaime Agudo Dec 14 '16 at 23:54
0

Just restart the XCode. It worked for me.

Rohit
  • 1
0

Make sure indexing has not been turned off (this was my problem). Here's how to turn it back on from the command line:

defaults write com.apple.dt.Xcode IDEIndexDisable 0

Eric Jorgensen
  • 1,682
  • 2
  • 14
  • 23
0

delete your custom cell(tableview cell) and add again with different name. It works.

Narasimha Nallamsetty
  • 1,215
  • 14
  • 16
0
  1. 'clean' Project
  2. lets complete indexing(if not completed)
  3. 'build' once
  4. check your issue is fixed
VikasK
  • 1
  • 1