The document "Main.storyboard" could not be be opened - ios

I'm using Git and we are 2 people coding together. I pulled my friend's code, run it and it worked as it should be. Then I merged our parts and cleaned conflicts (almost all of them were in storyboard). Since i'm doing this merge process for a while, i'm not all stranger for these details.
However, when i run the merged version of code, i get the error:
The document "Main.storyboard" could not be opened. The operation
couldn’t be completed. (com.apple.InterfaceBuilder error -1.)
I can't open storyboard as interface builder either. When i try it, I get the same error. I read previous post about this error but as I mentioned, I can open and run both versions of code in my XCode before merge. Thus, there is not a font or attributed string problem.
What may be the problem?

I got this issue, after I solve the conflicts which is merged by svn.
I could only see the source code of my storyboard, I could not open my storyboard as interface builder. So, after my struggle,
1)I delete the topside space line in my storyboard source code
2)and close my Xcode and simulator
3)restart my project
it becomes regular, oops, the space line on the source code will affect our storyboard !

there are conflicts in Storyboard. You can take last working code of storyboard from github. select storyboard select version editor and copy last working storyboard and replace xml with existing xml.

I guess your storyboard still have confliction.View your storyborad as source code, then fix all conflictions. After all, open it again as Interface builder

For me the only thing that worked was to create a new storyboard file, open the old and the new storyboards as source code, and copy the xml from the old to the new storyboard. I didn't take the whole xml, just the scope of the <scenes> </scenes>

I had to create a new Storyboard file. Then cut and paste the "scenes" tags from the old and put into the new. I then had to delete the old Storyboard from the project in order for the project to build successfully!

I guess the problem is that storyboards don't merge very well, I think it is better to init your UI from code so there will be no troubles during merges. Anyway you should try to rollback and merge it again.

As other mentioned, there are likely merge conflicts in the storyboard file.
If you can't easily solve the conflict by either picking --ours or --theirs, you will have to perform the merge manually in the storyboard file.
What I do is open in in a text editor (e.g., TextEdit.app - but make sure it opens documents as plain text, in Preferences).
Then, locate any occurrence of the git conflict markers (or a portion thereof, e.g., "<<<<<"), and pick the code fragment that you want to leave (and remove the other, of course).
EDIT: As Cong Tran mentioned (and I forgot), you can open storyboards as source code from within Xcode itself (see his answer).

Fast way to fix
Copy the storyboard Id shown on the error prompt window
Right click on your storyboard
Choose Open as => Source Code
Search the id and delete one of the duplicateID and you are done!

i would suggest , right click on any of the files and click on finder then you will have what you need and drag and drop

Related

Runtime warning: Could not load the image "imageName" referenced from a nib in the bundle with identifier "bundleId" [duplicate]

when I load my application it shows a warning message that
"Could not load the "" image referenced from a nib in the bundle with
identifier "
I searched and confirmed all my images. But it still shows that warning.
Select your image(s) in Project Navigator.
Open the File Inspector.
Make sure you have the target selected.
I had the same issue when I Refactor to Storyboard. Apparently the Asset catalog does not transfer the image reference. To fix, see below:
You would notice that your ImageViews is empty from reference.
1 - Click on the ImageView
2 Go to the Utilities bar where you would see you asset image is unknown
3 - Change it back to you image asset
This should fix your error. Hope this helps!
There might be many reasons of this error. To fix this issue you can just follow below given step:
Go to product menu of the Xcode, select clean.
If still you are getting the error, then remove the images from your project and again add the images to your project.
while adding image into the project, make sure that you have selected the Project name inside the "Add to targets". And also enable the "Copy items if needed".
Please Refer below image for better understanding:
Just select the image in Xcode and in right side, File inspector, under 'Target Membership' make sure your project is selected.
Another thing you can do is delete and re insert your image and make sure 'Copy items if needed' is selected and 'Add to targets' your project is selected.
Click on the image file in your Xcode navigator.
Once selected, go to the right side bar (of XCODE) which is
utilities and under file inspector, scroll to target membership and
select your project target file.
Then build and run the project again.
Xcode9 beta2 release note:
Jpeg assets in asset catalogs are not found on iOS 10 or earlier for apps built with Xcode 9. APIcalls for accessing the image such as UIImage.imageNamed: return nil. (32524123)
Workaround: Use png resources or limit app testing to devices running iOS 11 or later.
Xcode9 beta3 release note:
Jpeg assets in asset catalogs are found on iOS 10 or earlier for apps built with Xcode 9.(32524123)
For those that are getting this error while developing a cocoapod
I was trying to use an image from my pod's bundle, thats inside a .xcassets file, in the storyboard. It would show fine in the storyboard but when i ran the app it would crash saying it cant find the resource.
I changed my podspec to include s.resources as well as s.resource_bundles
s.resource_bundles = {
'SDKRes' => ['SDK/Assets/*']
}
s.resources = ['SDK/Assets/*.{xcassets}']
Then it was able to load the resource properly from the storyboard
You can try opening your storyboard or nib as Source Code and then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I have just updated to XCode 9 and it started giving me this issue. I created a new Image Set in the Assets section and added the images I wanted to this, then re-added them to my tab bar images with custom names and it worked fine. Hope this helps!
PROBLEM
This happened to me seemingly out of the blue on a tab bar controller with icons for each tab. The storyboard was still showing my image icons and the assets existed with the expected names.
MY FIX
Select the tab bar icons in their respective view controller and reassign the image like you did the first time.
This happened to me as well. I was doing everything right when adding the image but for some reason it was not working. I had to click on the image again once added, and then on the right toolbar under "Target Membership" I noticed my project was not selected even though I was selecting it when adding the image. I selected it here and everything worked fine.
I got the same error message (in XCode 8), even though the app ran fine (in the simulator and on the device).
I found the problem: In my storyboard, using the document outline pane, I clicked through every single UIImage, and looking at the attributes inspector for each UIImage - in the Image View section - found that one UIImage had a blank file name (instead of the .png file name containing the image). Reselecting the .png file name from the dropdown box fixed the error message.
I have fetching same issue in xcode 9.
just tick on target membership
I pulled my hair out over this issue for hours and none of the solutions in this thread worked. The problem, in the end, was that the Xcode project files were stored on a Google Drive file stream. As soon as I moved it to the local drive or iCloud it worked fine.
My case was a bit different. I was using an old IBDesignable element which had some property of setting an image directly from the storyboard. Since that element was old, hidden and unused the images it had were not present in my assets folder.
Now Xcode won't be able to search this image since it is not in the project anymore. But if you search in the finder, inside your project, you'll find the XIB/Storyboard in which it is mentioned. From there you can find it manually by opening that XIB or Storyboard as source code and search. Once found either replace them with a new image or remove the unused element.
Look into storyboard file you'll see a question mark icon on any of the imageView (as shown in screenshot below) or UIButton image.
Just correct it and the warning will be gone.
Hope this helps
My guess is that you have an image in the Project Setting->Build Phases->Copy Bundle Resources which loses its reference and appears in Red text color. Remove this image from there and re-add.
This happens often due to relocate the image file after adding into project where image was added as a reference instead of a copy.
May be this can fix your issue.
Urughhh. I tried to fix this with all the above solutions, but nothing worked. What finally worked was:
Delete image from your project and select Move to Trash
Clean project
Close and restart XCode
Rename your image filename so something other than the previous name
Add new image to your project
I was facing the same problem, I solve it by deleting folder and create again and past all images then add reference again.
Based on what #hstdt posted above, it made me think I should check that my image is a filetype that doesn't have any bugs related to it. (https://stackoverflow.com/a/44558948/6804257)
I was using a .gif. I got rid of that image and instead used a .png. Now it works.
Had the same issue and none of these answers worked for me. Instead I restarted the mac and iPhone I was working with and then everything started to work fine again. 🤷‍♂️
My case is difference. I have more one assets folder. So I added to the wrong one.
Just remove and add to the right.
In my case,removing and adding the assets folder from the target fixed the issue.
Xib sets a wrong name for folder reference images. For example I have the folder like Menu->icon.png. Xib sets the "icon" name for the image. It should be "Menu/icon". So do no set images in xibs if you use a folder reference images.

Could not load the "" image referenced from a nib in the bundle with identifier

when I load my application it shows a warning message that
"Could not load the "" image referenced from a nib in the bundle with
identifier "
I searched and confirmed all my images. But it still shows that warning.
Select your image(s) in Project Navigator.
Open the File Inspector.
Make sure you have the target selected.
I had the same issue when I Refactor to Storyboard. Apparently the Asset catalog does not transfer the image reference. To fix, see below:
You would notice that your ImageViews is empty from reference.
1 - Click on the ImageView
2 Go to the Utilities bar where you would see you asset image is unknown
3 - Change it back to you image asset
This should fix your error. Hope this helps!
There might be many reasons of this error. To fix this issue you can just follow below given step:
Go to product menu of the Xcode, select clean.
If still you are getting the error, then remove the images from your project and again add the images to your project.
while adding image into the project, make sure that you have selected the Project name inside the "Add to targets". And also enable the "Copy items if needed".
Please Refer below image for better understanding:
Just select the image in Xcode and in right side, File inspector, under 'Target Membership' make sure your project is selected.
Another thing you can do is delete and re insert your image and make sure 'Copy items if needed' is selected and 'Add to targets' your project is selected.
Click on the image file in your Xcode navigator.
Once selected, go to the right side bar (of XCODE) which is
utilities and under file inspector, scroll to target membership and
select your project target file.
Then build and run the project again.
Xcode9 beta2 release note:
Jpeg assets in asset catalogs are not found on iOS 10 or earlier for apps built with Xcode 9. APIcalls for accessing the image such as UIImage.imageNamed: return nil. (32524123)
Workaround: Use png resources or limit app testing to devices running iOS 11 or later.
Xcode9 beta3 release note:
Jpeg assets in asset catalogs are found on iOS 10 or earlier for apps built with Xcode 9.(32524123)
For those that are getting this error while developing a cocoapod
I was trying to use an image from my pod's bundle, thats inside a .xcassets file, in the storyboard. It would show fine in the storyboard but when i ran the app it would crash saying it cant find the resource.
I changed my podspec to include s.resources as well as s.resource_bundles
s.resource_bundles = {
'SDKRes' => ['SDK/Assets/*']
}
s.resources = ['SDK/Assets/*.{xcassets}']
Then it was able to load the resource properly from the storyboard
You can try opening your storyboard or nib as Source Code and then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I have just updated to XCode 9 and it started giving me this issue. I created a new Image Set in the Assets section and added the images I wanted to this, then re-added them to my tab bar images with custom names and it worked fine. Hope this helps!
PROBLEM
This happened to me seemingly out of the blue on a tab bar controller with icons for each tab. The storyboard was still showing my image icons and the assets existed with the expected names.
MY FIX
Select the tab bar icons in their respective view controller and reassign the image like you did the first time.
This happened to me as well. I was doing everything right when adding the image but for some reason it was not working. I had to click on the image again once added, and then on the right toolbar under "Target Membership" I noticed my project was not selected even though I was selecting it when adding the image. I selected it here and everything worked fine.
I got the same error message (in XCode 8), even though the app ran fine (in the simulator and on the device).
I found the problem: In my storyboard, using the document outline pane, I clicked through every single UIImage, and looking at the attributes inspector for each UIImage - in the Image View section - found that one UIImage had a blank file name (instead of the .png file name containing the image). Reselecting the .png file name from the dropdown box fixed the error message.
I have fetching same issue in xcode 9.
just tick on target membership
I pulled my hair out over this issue for hours and none of the solutions in this thread worked. The problem, in the end, was that the Xcode project files were stored on a Google Drive file stream. As soon as I moved it to the local drive or iCloud it worked fine.
My case was a bit different. I was using an old IBDesignable element which had some property of setting an image directly from the storyboard. Since that element was old, hidden and unused the images it had were not present in my assets folder.
Now Xcode won't be able to search this image since it is not in the project anymore. But if you search in the finder, inside your project, you'll find the XIB/Storyboard in which it is mentioned. From there you can find it manually by opening that XIB or Storyboard as source code and search. Once found either replace them with a new image or remove the unused element.
Look into storyboard file you'll see a question mark icon on any of the imageView (as shown in screenshot below) or UIButton image.
Just correct it and the warning will be gone.
Hope this helps
My guess is that you have an image in the Project Setting->Build Phases->Copy Bundle Resources which loses its reference and appears in Red text color. Remove this image from there and re-add.
This happens often due to relocate the image file after adding into project where image was added as a reference instead of a copy.
May be this can fix your issue.
Urughhh. I tried to fix this with all the above solutions, but nothing worked. What finally worked was:
Delete image from your project and select Move to Trash
Clean project
Close and restart XCode
Rename your image filename so something other than the previous name
Add new image to your project
I was facing the same problem, I solve it by deleting folder and create again and past all images then add reference again.
Based on what #hstdt posted above, it made me think I should check that my image is a filetype that doesn't have any bugs related to it. (https://stackoverflow.com/a/44558948/6804257)
I was using a .gif. I got rid of that image and instead used a .png. Now it works.
Had the same issue and none of these answers worked for me. Instead I restarted the mac and iPhone I was working with and then everything started to work fine again. 🤷‍♂️
My case is difference. I have more one assets folder. So I added to the wrong one.
Just remove and add to the right.
In my case,removing and adding the assets folder from the target fixed the issue.
Xib sets a wrong name for folder reference images. For example I have the folder like Menu->icon.png. Xib sets the "icon" name for the image. It should be "Menu/icon". So do no set images in xibs if you use a folder reference images.

StoryBoard Assistant Editor stopped showing associated file

Xcode storyboard assistant editor stopped showing related files.
"Automatic" is selected and "Class" is filled in Identity Inspector.
It was working before, but know it has stopped.
"Auto" or "CounterPart" modes are still woking for other files except StoryBoard.
A few days ago, I tried to update from Xcode 5 to 6, but later on gave up.
Would that have something to do with it?
With XCode 11 onwards, you can option(alt) + click on the file that you want to view in assistant editor.
Simple Fix.
Found the solution (at least worked for me), it's the same bug that causes you not to be able to create new outlets. You must delete the [DerivedData] folder:
Close the project you are working on with.
Delete the【DerivedData】folder of you project. (This folder may inside your project's folder, or inside
~/Library/Developer/XCode/DerivedData/(your project)/ ) or somewhere
else that were setup by you.
Restart Xcode.
see here.
In same case this worked for me:
Right click on ViewController file(on left pane) and choose Delete -> Remove Reference.
Right click on folder where this ViewController file was and choose Add files to .. and add this ViewController file which your just deleted.
Profit.
Deleting the Derived Data didn't work for me nor force quitting Xcode and restarting it.
The only thing that worked was deleting both the class and the storyboard (only the reference to them) and adding them back to the project.
Hope to help someone.
If anyone is wondering how to find Assistant editor in XCode 11 then
please find the steps from the below image. You can show this options
in storyboard or Xib files on upper left corner.
Maybe it's too late but just with the keyboard, you can launch a reset for associated files.
Use the keyboard :
command + option + shift + z
You can find it in the menu Xcode->View->Assistant Editor->Reset Editor.
Click first on the assistant window, then click on 'option'+'alt' and right click on the view controller that you want.
I have Xcode 13.1 and none of these solutions is working for me, but this simple solution works for me every single time. With your Storyboard and (empty) Assistant Editor open, in the upper right of the Editor window click the "Add Editor on Right" icon Editor On Right Icon, and just as promised, it will open a new editor to the right of your Storyboard and (broken) Assistant Editor, only the Assistant in THIS window will be working! Just find the "Close Window" x on your broken editor, close it, and in its place will be your shiny new working Assistant!
Full Editor View of where to click to open the new Editor On Right
Tried all the above methods whereas after simply running the app Command + B fixed this issue and I was able to select the screen under automatic.
This command on terminal fixed my issue:
defaults write com.apple.dt.XCode IDEIndexDisable 0
simply exiting and reopening Xcode worked for me.
For Xcode 8+ versions
Check at top process indicator that if Xcode is "indexing" files... if yes, then, please wait until it finishes. Once it get finished. Your file will automatically appear as counterpart in Automatic section.
If Xcode is not showing "indexing" in process bar, then perform as #Anna Chiara's Answer
I deleted ~/Library/Developer/XCode/DerivedData -> didn't work
Xcode->View->Assistant Editor->Reset Editor is disable
Finally, I figured out that the class name of File's Owner of .xib file is incorrect (the class doesn't exist). I corrected it and Assistant Editor works again.
Hope this helps you
I had the same problem. Finally this is what worked for me.
Changing the name of the ViewController File.
Change the name of the class to the new name via the Refactor tool
Refactor tool
The only thing that ended up working for me was copying over the code from the offending ViewController files and completely deleting them, then creating new ones with the exact same name and pasting in the previous code.
The assistant then linked up to the new ViewController files with no issue.
None of these answers worked for me w/ XCode 13. However, the following worked:
Rename the ViewController class to ViewController2
Update the reference in the storyboard to ViewController2
This made the assistant editor appear.
Change the name of the class back to ViewController. Change the reference in main.storyboard back to ViewController and hit enter (Step 2)
I had same issue and spent almost 2 hours of trying different aproaches finally I found something to solve problem.
I've created two or more VC at the same swift file and I think that's why IDE confused about the files.
So I suggest that you should delete your viewcontroller class and clean than reassign class.
I hope it works for you too.
For what it is worth, this was happening to me for the last couple days on 9.3 . I had just added a new build schema for an alternate debug symbol on testflight. It was not until I removed the new schema and then deleted Derived Data and restarted did it start working again. I have re-added the new schema back in and it continues to work. Not sure what the issue was, but that is what solved it for me.
In case anyone is watching I had a bizarre instance of this (Xcode 11): I deleted a View Controller that I'd done incorrectly; dropped in a new one, created the UIView and associated. BUT I didn't bother to create the outlet from the View Controller on the previous screen. Strange that it let me work for a few minutes, then after I had turned off the assistant editor to do something else, turned it back on and only had the UIResponder.h file. Edit - this happened again. Had to delete the 'wire' to the next screen, then recreate - then option to get to the correct .m and .h files reappeared.
I faced a similar issue and here's what I did
I had a swift file and a xib file with its class connected to the swift file like so inside a group folder, and it doesn't show that they're connected.
But when I take them off the folder the assistant works somehow, so I took them off the folder and made an outlet from a UILabel then put them back inside the folder then they're permenantly connected.
Quite Xcode and reopen it. This is solve my problem.
I had the same problem. But my problem was about having the VC's under "View Controller" folder. When I move VC's to main folder instead of "View Controller" folder, I was able to reach the assistant without problem. If you have the same issue like mine, you can solve by deleting all the VC's and create again under your sub folder.
Just add the Class on right side of your story board which you want to open in assistant

Storyboard crashes Xcode when opened

Whenever I attempt to open up my storyboard, Xcode crashes with the following error report
The funny thing is, the app works fine in the simulator and builds without errors. What is causing this crash? I see two possible crashes:
Exception reason: UITableView dataSource is not set
, but that shouldn't make the storyboard crash right?
Details: Failed to compute auto layout status IBLayoutConstraint, IBUIButton, IBUIDatePicker, IBUITextField, IBUIView, IBUIViewController, and IBUIViewControllerAutolayoutGuide.
Which doesn't give much information at all.
I have been using a storyboard with Xcode 5 for some time, so the question does not appear to be related to moving from Xcode 4 to 5. I can open the storyboard as XML and I can open my iPhone storyboard just fine.
If you are using git, I would recommend reverting to a time before this problem started.
If you are not using git, and you are absolutely sure you did not edit the xml for the storyboard then I would say:
1)find the storyboard file using the finder.
2)copy it to your desktop.
3)go back to Xcode and delete the storyboard from your project, select "move to trash". 4)re-import the storyboard file into your project.
Ive had similar problems with Xcode 5 and either reverting using git or the steps above usually get me back up and running.
Exception reason: UITableView dataSource is not set
Details: Failed to compute auto layout status IBLayoutConstraint, IBUIButton, IBUIDatePicker, IBUITextField, IBUIView, IBUIViewController, and IBUIViewControllerAutolayoutGuide.
The errors described above lead me to think that one if not all viewcontroller(s) for the items listed above lost their connectivity to viewcontroller.h / viewcontroller.m files. I would make sure you have everything wired up correctly, and you can check this by making sure the items in your viewcontroller have a circle in the gutter (next to the line numbers) that is filled in (solid) if the circle is not filled in then it means your items are not wired up to your viewcontroller. I would post a picture of your .h / .m file of your viewcontroller so we can further investigate.
I ended up copying each view controller scene (in XML) into a new storyboard. Some view controllers could not be copied without the storyboard crashing so I had to recreate about 4 of them, but by and large I got the majority of my work back.
What you need to do is reopen the project again in Xcode 5 and then go to the storyboard. Then at the right side choose for "Identity and type" and then set "opens in" to Xcode 4.6 to be able to open it in Xcode 4.6. And disable auto layout, somehow when you open it in xcode 5 it asks you to update it, I think you did that without a thought, happened to me as well :)

Xcode 4: Creating a UIView xib, not properly connecting

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:
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.
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!
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.)
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.
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.
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!
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.
This helped me out:
from the project file Panel (left side) select the xib file that is broken.
Click on the Files Owner icon from the editor view.
from the properties Panel (right side) select the third tab (at the top)
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.
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.
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.
in XCode go to organizer, click project, click delete derived data... than clean the project
In my case it helped to make a "fake change" (just a space) to the according header file.
ResultCell should be a subclass of UITableViewCell
You should not drag a UIView onto the empty canvas, you should drag a UITableViewCell
You should select the cell and change it to be your subclass
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
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
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.
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...
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:
Clean the project
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.
Alternatively, in the File Inspector (Utilities view) of the NIB file, under Target Membership, uncheck and check back the target name.
Restart Xcode for good measure.
Of course, deleting and adding back the .m file alone should fix it too.
(Steps 1 and 2 alone fixed it for me.)
If you copied files from other project just make sure you check the 'Add to targets' box
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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!
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.
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
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.
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

Resources