13

This is a real 'WTF?' moment for me.

I copied some classes out from another project, including copy and pasting the code and some UIBulder components. What did NOT get copied was the XIB file (I went from XIB to storyboard).

My tab / swipe recognizers aren't activating, and when I drill down the only thing I can discover that can explain it is that somehow, someway, I'm hooking up against the XIB file. (When I click on the little button next to the IBAction/IBOutlet lines in the header, it shows me both the storyboard and the xib file as connected).

I'm not referencing that file anywhere that I can find, it's just somehow magically recognized in Xcode. I don't know what to do, how to fix this.

Anyone have any ideas?

Edit: The really annoying bit is that the file doesn't appear to be in my files list when I check there, I can't just delete the reference that way. And since it's referencing the file in the original project, I can't just delete it. (Any changes made in either project cause changes in BOTH projects; their both using the same xib file for some reason). I should be able to simply delete the reference to the xib file, but I can't find the reference.

RonLugge
  • 5,086
  • 5
  • 33
  • 61
  • Right now I'm having the same problem, I just Copy and Past one xib from the original project to the modified project that I'm working on (it's the same project, but the I just the an old copy to compare or something) And right now the header file it's pointing to a xib that I don't have in my proyect, and the new xib doesn't have those connections. I'm not sure how to fix this problem – Juancarlos Rodríguez Nov 25 '13 at 13:52
  • I am still having this problem, even after trying the solutions below. Everytime I re-open both projects the connections return... – Jacob Aug 27 '14 at 22:04
  • I am as well. It is a rather ridiculous problem to have. – Siriss Nov 03 '14 at 19:56
  • @Jacob (and Siriss) let me suggest you guys go ahead and delete the first project. Or at least, use the finder to physically change the physical location, in a manner that is totally isolated from XCode (so it can't try to restore them). – RonLugge Nov 04 '14 at 16:19

4 Answers4

17

If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets.

enter image description here

If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.

Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Right click your views in the storyboard to see what referencing outlets really exist in the current project. (See my fuller answer for more details.)

No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior.

The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore the little circle.

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • Thanks for the reassurance, still drives me nuts, though. If you simply make a new class with a different name will that make them go away? – Ethan Parker Nov 29 '16 at 17:40
  • @EthanParker: Yes, as long as the class name or the outlet name are different, then Xcode won't get confused. – Suragch Nov 30 '16 at 00:05
13

I just had the same problem. What solved it for me was to close both projects, delete the derived data from both and then reopen the destination project.

I agree, it's a crazy problem.

Matt Becker
  • 2,338
  • 1
  • 28
  • 36
  • This solves it. However if now open the original project again, the links will re-appear ... – Kitetaka Mar 12 '15 at 17:36
  • Deleting the derived data folders for both projects solved it for me. – Shantanu May 05 '15 at 06:24
  • 1
    As the [Alex Zavatone comment](http://stackoverflow.com/a/20195260/419348) said, after reopen the project that the header is linked to, the problem will come back. – AechoLiu Dec 31 '15 at 05:39
3

I'm sure that this problem could happen and I fix it deleting the content of the Derived data folder of XCode.

I just want to add the steps of how to delete those files:

  1. Don't Delete the DerivedData folder.
  2. Go to preferences (Command ,) > Locations Tab
  3. On Derived Data you are going to see the path, clic the right pointing arrow (that will open that location in Finder)
  4. Close XCode
  5. Select all the files inside the DerivedData Folder (do NOT select parent folder) and (Command Delete) or move them to the Trash and then Empty Trash
  6. Open the project and you are done

I hope it helps someone

Juancarlos Rodríguez
  • 1,574
  • 2
  • 12
  • 11
  • 2
    Actually, if you reopen the project that the header is linked to, you'll still see the connections to the storyboard in the other project. Even after quitting and restarting Xcode. – Alex Zavatone Apr 10 '14 at 20:10
  • Worked great for me!! – Scooter Aug 06 '15 at 21:41
  • 1
    So this happened to me again in xcode 7.0, and I completely forgot about this solution, spent a ton of time googling trying to solve the problem, only to stumble on this solution again and find the above comment from ME saying what a great answer this was. Awesome. – Scooter Nov 08 '15 at 23:20
1

unless the xib file is in the project. it should not have a link to it.

the xib file connects to the .h file. not the other way around.

You may want to remove the connections in the storyboard and re-connect them.

Also make sure that the storyboard is the UI being started and that the item on the navigation stack is actually the storyboard page. But you should be able to connect both the storyboard and the xib file to the class at the same time. You just cannot connect one IBOutlet to more than one object in a single ui component (e.g. two buttons on the storyboard cannot both be connected to @property IBOutlet UIButton *myCurrentButton you must have a separate IBOutlet for each connection. On the other hand, any number of actions can be connected to an IBAction. which is why you get (id) sender on each action.

I dont know if this is exactly what you are experiencing, but I hope that understanding helps you debug your issue.

The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69
  • 1
    What you said confirms most of my confusion. I wound up deleting the temporary files, and relocating the second project. That broke the connection to the file from the second project -- but alas, it didn't fix the actual problem. Turns out that's a bug elsewhere. – RonLugge Aug 22 '12 at 20:28
  • you can click on the connection bubble. and select the xib that the connection relates to. it should open in xcode. perhaps it actually is a part of your project and that is why it is appearing. You may try deleting the DerivedData folder. right click the target and show in finder. then move up in the tree to get to the DerivedData folder so you can delete it. You will then want to clean the project and rebuild. – The Lazy Coder Aug 22 '12 at 20:34
  • Clicking on the bubble is how I determined that somehow, this project is referencing a file from the external project. And it turns out moving that folder only temporarily broke the reference, as soon as I moved the project back the reference returned. Could you better explain your derived data explanation? (I usually delete drived data from organizer...) – RonLugge Aug 22 '12 at 20:37
  • i move my derived data folder to my project location. You can do this in xcode preferences. select the locations tab and put derived data to "relative" this will place it in the workspace folder. a lot of times I have to delete the entire directory because it builds indexes and puts them in there. But. xib files should not be included unless they are in the project, or in the project directory. If you click on the item in the bubble it will open. What location does it show at the top of the view. Its likely that it is in your project. – The Lazy Coder Aug 22 '12 at 21:50
  • Somewhere along the lines, cleaning, deleting the derived data, and moving the folders around appears to have permanently broken the original link, even when I move the folders back to their original locations. (I think it may have been the clean I was missing on my first try; maybe I cleaned then deleted derived?) ANyway, thank you very much for your help. – RonLugge Aug 22 '12 at 22:19
  • no problem. glad it got sorted out. BTW I have to delete DerivedData so often its more convenient to put it into my Project folder and delete it from finder. I hope apple fixes this, but deleting it fixes a lot of things. Including Autocomplete. You may want to check Xcode > Preferences > Location. you can put it where you want. and you dont have to hunt it down. – The Lazy Coder Aug 22 '12 at 22:22
  • 3
    THere's actually a quick and easy way built in -- in the organizer, under project details, a simple 'delete derived data' button. – RonLugge Aug 22 '12 at 22:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15688/discussion-between-ronlugge-and-volure-darkangel) – RonLugge Aug 22 '12 at 22:30