84

I'm trying to create a nib that contains a view that will be embedded in a TableViewCell. I've created the interface and implementation files, ResultCell.h and ResultCell.m. They're stock, out-of-the-box, no code changes.

I then create an empty XIB file, and drag a UIView onto it. Then I click File's Owner, and set the type to ResultCell. I click the view, and set its class to also be ResultCell.

Here are the problems I have:

  1. When using the Assistant Editor view (which I live in), the ResultCell.h file doesn't appear when I'm viewing the ResultCell.xib file. I have to force it to load by clicking on Automatic and selecting the file.
  2. When I drop a label in the view, and then Ctrl+Click and drag to the .h to create an outlet, I get this error message: "Could not insert new outlet connection: Could not find any information about the class named ResultCell."

I've tried creating and re-creating the view, and it's just not working, and I've started to lose my patience. Any help would be very, very appreciated!

bneely
  • 9,083
  • 4
  • 38
  • 46
Tim Sullivan
  • 16,808
  • 11
  • 74
  • 120
  • I just ran into this myself. Last night it worked and today nothing. I'll let you know if I find anything. – Tavison Jul 15 '11 at 06:43
  • For the record, multiple answers here have helped me over the last year. Recent versions of Xcode have improved things. – Tim Sullivan Jul 07 '12 at 16:45

33 Answers33

113

I got into a similar state just today. It was very odd: I could attach any XIB (new or existing) to any already-existing ViewController class in the project, but I could not create a new ViewController and have it attach properly to any XIB. The "assistant" functionality didn't work, nor did the IB-to-headerfile-connection functionality.

Closing the project and re-opening did not fix it.
Quitting XCode and restarting did not fix it.
Creating a new project and testing the functionality worked fine, which led me to believe there was something corrupt in some cache somewhere.

My solution

  • Close your project.
  • Go to the ~/Library/Developer/XCode/DerivedData folder and REMOVE all subfolders there referencing the project you are working on.
  • Open your project in XCode. The problem should be fixed now.

Incidentally, just running a full clean did not seem to clear things up. I had to trash the derived data. I'm certain I got into this position because of git games I was playing, but I had no idea how to get out, because even switching back to earlier git revisions didn't help. (That was a big clue also that it was something untracked by the project itself.)

David Pisoni
  • 3,317
  • 2
  • 25
  • 35
  • 6
    I just logged into SO on my Mac, just so I could upvote this answer! Totally worked for me. This was driving me crazy, as I am just learning to use XCode and it is already hard enough without ridiculous problems like these. :) Thank you!!! – Dave Apr 25 '12 at 23:05
  • 2
    it even works without restarting xcode; just deleting derived data and rebuilding (on a iOS project) – nob Jun 28 '12 at 11:14
  • This worked when restarting xcode did not. I have no idea how it happened by David Pisoni's method worked great. – mmopy Aug 13 '12 at 18:49
  • Awesome. How did you know that? Worked for me. – hol Sep 02 '12 at 12:06
  • @hol:like I said, the big clue was that I couldn't effect any change to state by changing something tracked within the project. Once I determined that, I went hunting elsewhere... – David Pisoni Sep 02 '12 at 19:20
  • 1
    lol its good to know that IOS and xcode can be just as buggy if not more so than using eclipse and Android :p – James andresakis Oct 17 '12 at 06:24
  • IMHO that's a stretch... Thus far I haven't grown any gray hairs from Xcode. I can't say as much for Eclipse, which frequently makes we want to run around screaming. :) – David Pisoni Oct 18 '12 at 18:41
  • This approached worked for me also. Given the number of up-votes it might be time for @TimSullivan to consider making this the accepted answer? – PaulJ Oct 22 '12 at 11:41
  • Xcode 4.5.2 here. I can not believe this issue has been around for so long and is still around. – Enrico Susatyo Jan 16 '13 at 06:23
  • I have same issue with 5.0.2. Tried everything. – expert Nov 06 '13 at 23:27
  • Deleting all the subfolders of the DerivedData folder solved my issue! Thank you. – Cesare Jan 21 '15 at 20:07
  • It seems after all this time that I hit on the right answer. Maybe the original questioner can mark this answer as correct so it floats to the top? (Presuming you're still subscribed...) – David Pisoni Jan 21 '15 at 20:17
81

This might not work for your specific issue, but occasionally I get that error when working with newly created nibs. Deleting and recreating the nibs and View Controllers with the same names as before didn't resolve the issue, but relaunching Xcode did.

Defragged
  • 1,914
  • 15
  • 15
  • +1 Worked for me too. Just restart XCode, and now I can CTRL+Drag to create new @propertys in my .h file. – Mike Gledhill Nov 16 '11 at 12:41
  • 1
    David Pisoni answer worked for me. Simply restarting Xcode didn't cut the mustard. – Andy May 16 '12 at 16:49
  • I've not had this problem occur for many Xcode releases now, so there's probably another cause which is more prevalent now than the one I was experiencing when I wrote this answer last year. – Defragged May 17 '12 at 08:42
  • @Defragged can you also include the step to clear cache by pressing Command K before quoting or even better is to quit Xcode then clear cache (`~/Library/Developer/Xcode/DerivedData`) – user1046037 Apr 22 '13 at 04:30
  • I'm working with Xamarin Studio. I had to quit xcode and xamarin studio then reopen Xamamrin Studio and open a xib file from here which launched in xcode. The assistant editor then opened correctly. – Dave Haigh Sep 12 '13 at 11:33
  • Mindboggingly this is still a problem in mid 2014 and I don't know how many versions of Xcode later. – Teo Sartori Jun 25 '14 at 12:23
  • Restarting Xcode 6.1 (using a Swift project) worked for me and fixed the error. – King-Wizard Dec 01 '14 at 17:56
  • I had this same problem (Xcode 7.x, Swift 2.x), different solution in my case. I tried everything listed in the comments (blowing away derived data, restarting Xcode, clean build, etc., and those listed here http://stackoverflow.com/questions/15288773/could-not-insert-new-outlet-connection). What worked: my viewcontroller file was outside the target in the navigation panel. I dragged and dropped it nice and cozy next to the app delegate, checked the box "Copy If Needed", and deleted the old one. Hope it helps someone. – AmitaiB Feb 04 '16 at 19:01
14

I just had this problem and restarting Xcode did not fix it. I removed the class files from the project then added them back in and it started working.

jasongregori
  • 11,451
  • 5
  • 43
  • 41
13

I had the very same issue. And I tried :

  • Restarting Xcode
  • Deleting Derived Data
  • And many more

None of that worked. What worked for me was simply to :

  • Remove 'suspect' class files from Project (just remove References, huh?)
  • Re-add them to the project

And done!

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • 2
    This worked for me, thank you! It was the first thing I tried, other than restarting XCode, since it seemed like the least amount of work and risk, and it worked great. – adriandz Jun 06 '12 at 16:51
  • 1
    worked for me after restarting xcode and deleting derived data didnt – elad s Apr 17 '13 at 08:29
  • 1
    This one did the trick for me too. This may have something to do with refactoring the class names (which is what I just did before). – ecotax Apr 23 '13 at 14:21
9

If restarting Xcode doesn't work of you, I have found that Toggling the new .m file out and back into the target membership works.

Duane Fields
  • 1,331
  • 12
  • 20
3

This helped me out:

  1. from the project file Panel (left side) select the xib file that is broken.
  2. Click on the Files Owner icon from the editor view.
  3. from the properties Panel (right side) select the third tab (at the top)
  4. specify the "Custom Class"

If you do not see a "panel", please have a look at the top-right corner of the window and enable the proper "view" buttons. If you don't see the "view" buttons then click on the top-right most capsule button.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
Ivan Dossev
  • 565
  • 5
  • 11
  • I had recently changed (refactor) the class name. The custom class as mentioned in this answer was still set to the old name. Changed it to the new name and it's fixed. – PaulMrG Jul 07 '13 at 16:45
2

I encountered the same problem today. Restarting XCode did not fix the problem for me. I was able to get things back to normal by using "Delete" option of "Derived Data" of the project that can be found under Organizer. Organizer says that, "Derived Data includes index, build output and logs". I guess that either index or build output was causing this issue.

Praveen Kumar
  • 1,280
  • 1
  • 8
  • 14
2

in XCode go to organizer, click project, click delete derived data... than clean the project

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
2

In my case it helped to make a "fake change" (just a space) to the according header file.

jakob.j
  • 942
  • 13
  • 28
  • I think this may have done it for me too. In my case I added an outlet manually. I was then able to connect my noodles to it, as well as create new outlets by ctrl-dragging. – Daniel Wood Sep 05 '13 at 14:50
2

I noticed that .m file was moved inside en.lproj folder.

Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.It will fix the issue.

Don't worry, you will get all your connections back.

A.S.
  • 320
  • 3
  • 11
  • My .m was autogenerated and I hadn't changed it yet. I did and everything was OK. Nothing else had worked. – entonio Aug 26 '13 at 22:00
1

Perhaps what worked for me is this.. (Xcode v4.5)

This did not work

I was trying to control drag into the interface definition of my .h

@interface SearchViewController : UIViewController

@end

This worked (may be that is how it was supposed to work, I did not know it before) See the open and close brackets. Control drag and drop after the closed bracket.

@interface SearchViewController : UIViewController
{
}

@end
Mouli
  • 165
  • 2
  • 12
1

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

Jamal
  • 763
  • 7
  • 22
  • 32
codeburn
  • 1,994
  • 17
  • 20
1

None of the above workarounds resolved the connector issue for me so I shelved my pet project until I came across the following stackoverflow thread:

https://stackoverflow.com/a/15873770/2846800

I had been working on a large project in a previous version of XCode and had turned off indexing. By re-enabling indexing my issue is now fixed:

defaults delete com.apple.dt.XCode IDEIndexDisable

I can now use the D&D features of Interface Builder. I hope this can help others...

Community
  • 1
  • 1
1

I had a similar problem with a project written in Swift.

What worked for me was setting up the IBOutlet in code like this

@IBOutlet var foo: UIView?

and afterwards connect it to Interface Builder by dragging to the little circle that appeared right next to the code line.

Patrick
  • 137
  • 1
  • 8
  • This is the ONLY way I was able to get it to work for me too. I was following an Apple tutorial written for Objective-C (Start Developing iOS Apps Today) and needed to connect the New To-Do Item text field. Finally I created @IBOutlet var textField: UITextField? and connected to that, and it worked. Using XCode 6.4 – andrewz Jul 30 '15 at 16:09
1
  1. ResultCell should be a subclass of UITableViewCell
  2. You should not drag a UIView onto the empty canvas, you should drag a UITableViewCell
  3. You should select the cell and change it to be your subclass
  4. The owner is most often a controller with an outlet to the cell

Everytime you want to load a new cell, call:

 [[NSBundle mainBundle] loadNibNamed:nibName 
                               owner:controllerWithOutletToCell 
                             options:nil]

after loading, use the cell, and set the ivar/outlet to nil, ready for the next load

there are other ways, but this is common

bshirley
  • 8,217
  • 1
  • 37
  • 43
  • If I do that, I have exactly the same problem. The Assistant Editor doesn't display the .h when I'm viewing the nib, and the ctrl+drag doesn't create the outlet code, it displays the error. – Tim Sullivan Jul 15 '11 at 07:06
  • 2
    Are you using 4.0.2 Xcode? You can manually set the assistant editor if it's misbehaving. I assume you've restarted the app to retest this problem (Xcode 4 often benefits from this). Sounds like it can't find the class files in the project, or something is misnamed - capitalization important. Is the project currently building? This is a very high level functionality that depends on the new compiler technology. – bshirley Jul 15 '11 at 14:55
  • Aw, eff me. Yeah, restarting Xcode and it immediately started working. 'Scuse me, I'm going to go fall on my sword now. – Tim Sullivan Jul 15 '11 at 15:26
0

If you copied files from other project just make sure you check the 'Add to targets' box

John67
  • 321
  • 1
  • 2
  • 12
0

Renaming the class files may unlink them from the XIB. This answer helped me discover this:

Ctrl-Drag from button to method not working. Xcode/Interface Builder

Check that your custom class is set correctly in the Identity Inspector.

Community
  • 1
  • 1
0

Similar symptom, but different cause.

Apparently I hit backspace when the focus was on the assistant view, because one of the standard file template comment lines went from // to / which results in the file not compiling.

Fixing the comment allowed the SDK to parse the file, recognize it as a UIViewController, and add in the outlet.

SO -- if you have this problem, do a build or analyze to see if there are errors that need fixing in your view controller .h file. THEN try the other solutions.

software evolved
  • 4,314
  • 35
  • 45
0

This might be an old topic but just in case anyone has the same issue in future, try deleting the associated .xib,.h and .m files and create new ones. For me, the UIViewController in my .h file wasn't purple and even backspacing and typing it didn't help.

S.G.
  • 71
  • 3
0

Just put a line between the @implementation and the @synthesize. Most of the answers here have that in common. It worked for me

@implementation 

@synthesize
0

I just tried everything here and nothing worked (using a Developer Preview for Xcode 5).

The only thing that worked for me was to put this incomplete line in my interface file:

@property (nonatomic, weak)

For whatever reason, adding outlets and actions by drag and drop from a .xib worked fine after that.

djibouti33
  • 12,102
  • 9
  • 83
  • 116
0

For me wether cleaning nor deleting the DerivedData solved the problem.

I tried to delete and recreate my UIViewController class several times and got the problem again and again.

Then I recreated the UIViewController class and gave it a different name. This solved the problem for me.

0

I have had this problem and found a solution not listed above.

In my case, I could see there was something wrong in the class .h file because my custom view controller did not recognise the class : UIViewController (it was in black not purple). All the other custom view controllers had the : UIViewController in purple.

in my case, and possibly yours, I needed to add the class to targets/build phases/compile Sources drop down. The .m needs to be added. All of the other .m's were there but not this one.

Once I added it, the :UIViewController appeared in purple and everything worked fine.

0

For my case, I have multiple project with some other dependencies. I tried to solve it by deleting derived data or restarting XCode but it couldn't work. In the end, I tried the following method and it works:

Go to target > Build Target Architectures Only > and set both Debug and Release to NO.

Set this for all projects in the workspace and recompile to make sure there is no other errors. Maybe not making sense but somehow did it. During my compilation, I had other issues such as linker errors and symbols not found.

morph85
  • 807
  • 10
  • 18
0

For *.m file of this class view open "Show File Inspector" and unchecking "Target membership" for this project, then do Clean (menu Product->Clean) and checking again "Target membership" for this project

enter image description here

Kozlov V
  • 146
  • 5
  • 17
0

Using Swift, I had a similar problem. I found out that the comments were part of the problem for me.

I leveraged the default view controller, did some work in it, then created a second view controller by copying the entire first one, stripping it down to only viewDidLoad() and renaming the class to TestViewController. Builds worked, code executed. All was good.

When I went to drag a UITextField in to create an outlet, it would not let me. I noticed that my comments still said "ViewController.swift", so I changed the comment text to "TestViewController.swift" and rebuilt. I was able to connect my outlet!

I wonder if what occurred is that the Indexer was reading the comments as well as the class names, and somehow got confused.

Antonio Ciolino
  • 546
  • 5
  • 16
0

Hope this helps someone out there.

I just had to delete the derived data folder. You need to click Window -> Organizer -> Projects -> Delete Derived Data

AND RESTART XCODE.

You should be good to go!

TheRealRonDez
  • 2,807
  • 2
  • 30
  • 40
0

The new class not being part of the "TARGET" is likely the root cause of this, as alluded to by some of these answers.

When creating a new cocoa class, by default the option to add new class to target is by default checked, but should, for any reason, this not be checked when you hit save, you will have this issue.

New Class Target

Any of these workarounds that add the new class to the apps target will work to resolve the problem, and is something that all these 'fixes' have in common.

I think XCode likely has some bugs that causes a new file to, by default, NOT be added to the apps main target. The fix boils down to adding your 'broken' class to the main TARGET

Michael Bopp
  • 656
  • 1
  • 4
  • 13
0

In XCode 7.1, adding the connector at a different point in my source file worked. The error I was getting referred to one of my variables as if it were a class (didn't make any sense). The error stopped occurring when I added the connector below that variable instead of above it.

user2683747
  • 151
  • 1
  • 9
0

There is also a diferent reason for the issue ... if you have created new cocoa class file with template other than ios ... i can happen...

The solution would be to delete it and re create it with right template enter image description here

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
0

I've got the same issue. Rebuilding project helps me Command+B.

0

When I try to auto generate the action function with below way I came this issue.

enter image description here

But I can done it with below, manual write the action function first, then drag on the region of the @IBAction funciton

LF00
  • 27,015
  • 29
  • 156
  • 295
0

I Just ran into this today on Xcode 12.1.

I did the typical delete derived data, and even restarted my computer, but no luck.

In the end I was able to fix this by.

  1. Selecting the View Controller in IB
  2. Change the class name in the right hand panel under Custom Class > Class to a random class name
  3. Change the class name back to the correct class name.
TMin
  • 2,280
  • 1
  • 25
  • 34