“Could not find any information for class named Vi

2019-01-12 23:45发布

问题:

This bug has been driving me nuts since I started using Xcode (4.6.3). Whenever I try to link a Storyboard item to my code, I get the error:

Could not find any information for class named ViewController.

This happens with custom classes as well. I've tried methods such as:

  • Deleting the delegate data.
  • Removing and re-adding the classes.
  • Restarting Xcode.
  • Reinstalling Xcode.

I can't ctrl-drag to create connections in any of my projects no matter what the class is. The same problem happens with a brand-new template application. If I type in the code manually and then ctrl-drag, I can make a working connection, but I can't add it automatically. Nothing I've been able to find so far on the Internet has helped. Any pointers?

回答1:

What solved this issue for me was actually deleting the class from the project.

Steps:

  1. In the project file explorer (left panel) find the class and right click -> Delete
  2. Remove reference (do not move to trash as you will lose the class for good)
  3. Right click on the folder that contained the class -> Add files to ...
  4. Find the class you just deleted in the file system

This seems to force Xcode to link the class back into the storyboard.

Note: for me the following did not work:

  • Closing Xcode
  • Cleaning the project
  • Deleting the class name from the storyboard and re-entering it

I think this is a bug on Apple's part



回答2:

In case anyone is still frustrated by this, there's a trick to get things working.

What I do is manually enter an outlet into my class, for example: @IBOutlet weak var someView: UIView!, and drag from the code to the view in IB or storyboard. After this, I am able to drag from IB / Storyboard to my class to make connections, assistant editors recognizes the class in "Automatic", etc...

Works every time.



回答3:

For me removing them from your target membership in the right column and adding them again did the trick



回答4:

Sometime Xcode does due to VC not referencing class file. The simple solution for this is:

write property manually as given.

class YourClassName{

     @IBOutlet weak var YourTableName: UITableView!

}

This will make a empty link sign before @IBOutlet, open your project in assistant editor then click link sign and drag into the View which you want to connect (i have connected with TableView). and thats it. Enjoy Happy Coding!!!



回答5:

the following steps works for me hope that works for you also

1- You need to reopen you project after closing Xcode.

2- Wait for indexing project files

3- Check if it work or not

4- If still not working follow step 5, if not happy for you :)

5- Clean and Build your project target



回答6:

I just had this problem on April 2017 with Xcode 8

Simply creating an outlet through code and compiling fixed it. eg:

@IBOutlet weak var containerViewHeight: NSLayoutConstraint!

You got to love Xcode…

Edit: Still happening on Xcode 9



回答7:

For me, the following worked:

  1. Do a 'clean' and a 'clean build folder' (press 'option' on the Product menu to get the 'clean build folder' command

  2. Stop Xcode

  3. In terminal, go to the derived data folder:

    (/Users//Library/Developer/Xcode/DerivedData)

Delete the derived data dir for your project.

  1. Wave dead chicken in the air

  2. Start Xcode



回答8:

I tried everything and it didn't work, so for me what worked is:

  • Clean Build folder and project.
  • Open Projects (Window -> Projects)
  • Find your project on the list and delete the Derived Data
  • Close Xcode
  • Restart computer (without choosing to reopen windows that are open)
  • run Xcode
  • Work!

All my view controllers were not being recognized, so deleting all files and re-adding was not an option as this is a big project.



回答9:

I had to do a combination of a couple of the answers so far:

  1. Remove the custom class name from the storyboard.

(Click the yellow button at the top left of the view controller in the storyboard -> go to the identity inspector (option + command + 3) -> delete the custom class name at the top)

  1. Remove the reference to the view controller file.

(Right-click the file -> delete -> remove reference)

  1. Add the view controller file back to the project.

(Right click the folder where the file was -> "Add file to [project]")

  1. Add the custom class name back to the storyboard.


回答10:

If people try the above and things are still not working, the strange trick that worked for me was adding the outlet in a chunk of whitespace. It works if there are no other lines directly above or below the line you're adding. Strange, but it worked!



回答11:

What worked for me was, instead of dragging the connection from the button to the code, was:

  1. Clicking the desired storyboard item.
  2. Opening the connection inspector (right panel)
  3. Dragging from the + circle to the area of code. Like so:

after I linked my code in this way, it worked normally from thereafter.



回答12:

I tried all of these answers, the problem for me was related to Xcode not being able to index the files. I fixed this by simply quitting Xcode and reopening the project. Of course I did that after trying all of the above solutions :p



回答13:

Product > Clean (Command - Shift - K) fixed it for me!



回答14:

This is the EASIEST step that I did to fix this problem.

  1. I clean the project
  2. Drag a new button in the view controller.
  3. Build the project.
  4. Connect the newly dragged the button to the class (either outlet or action).
  5. Then voila!!! Other outlets can now be connected to the class again!


回答15:

Stay On Target!

I was adding a new class with a Xib and I started seeing this issue and I spent a goodly time looking through the answers on here and seeing if any of it made a difference to it.

As it happens, I have multiple targets in my workspace and often I have to switch between them.

Turns out adding new files will kick start a re-index in Xcode. But if you are pointing at the wrong target then the indexing is likely to meaningless and during the drag to connect Xcode will not be able to find your class.

In short

Step 1.

Make sure you have the correct target set so that indexing makes sense.



回答16:

This worked for me:

  1. Perform 'Clean build folder'
    (press and hold the 'option' key and go to the "Product" menu to access it.
  2. Perform a simple "Clean" (CMD-SHIFT-K) from the "Product" menu.
  3. Build the project to let Xcode compile the files. Also, let it index files if necessary.

On a side note, I am not sure if this helped but I also deleted the Derived data before performing the above steps (Xcode preferences > Locations)



回答17:

Select the ViewController in storyBoard, delete current value in Right hand panel/"Customer class"/"class" then re-add control class (type: "SampleViewController"...), enter. --> That work for me



回答18:

As my testing experience,if you delete a class which was associated in the Xcode,and than add file again,than this issue will occur.



回答19:

Usually when this happens to me I just haven't saved the code for the class yet. Just hop over to the code and hit cmd+s and it often fixes the problem right way.



回答20:

Just need to clean and re-build the project.



回答21:

I was getting a similar problem, "Could not find a class named..." and the cause was stupid on my part once I figured it out. Make sure you aren't dragging from the item to the interface - make sure it's being dragged to the class itself



回答22:

I would try to remake the .m and .h files in question and give them an original name, not generic like "ViewController". Try something more along the lines of what you want that file to do, and ending in View Controller (i.e. "PizzaDecoraterViewController")

Then select the ViewController that you want to connect to those files. Make sure that you select the ViewController, not just an object within. Click the black bar at the bottom (the one that has the "First Responder" and "Exit" icons). The entire ViewController should outline blue. Then go to the Custom Class section in the Identity Inspector and you should see a grayed out "UIViewController" in the first field. In that field, type in the name of the .h or .m file that you want it to connect to (Start typing PizzaDecorator... and it should do a little auto-complete thing). Then hit ENTER.

When you open up the Assistant Editor, make sure that the file that you are trying to drag and drop to is, in fact, the correct file.

If you have done all as said above, then it should work.



回答23:

Delete the files (only the references) and add the files again.



回答24:

Well in my case, the thing that worked (it's a litle weird, but worked) is the following:

Try to add a datasource (ex. an extension to the ViewController like a UITableViewDataSource). Xcode will try to reload the ViewController. Then I wrote some method of the protocol (in the beginning Xcode did not autocomplete the methods, but wrote it out manually), then I added the IBOutlets, and then lastly, I removed the datasource.

Example:

class TestViewController:UIViewController{
    // This viewController presents “Could not find any information for  class named ViewController”
}

extension TestViewController:UITableViewDataSource{
    //Add Some methods of the protocol, Xcode will try to autocomplete and then it's going to reload the class, from then you can add your IBOulets / Actions .. And remove this extension if you don't need it otherwise.
}


回答25:

For me, the view I had specified a custom class for was failing to be compiled by interface builder. It was marked @IBDesignable.

Removing @IBDesignable, and then adding my outlets, and then marking it as @IBDesignable resolved the issue in my case.



回答26:

just try this

rm -rf ~/Library/Caches/com.apple.dt.Xcode
defaults delete com.apple.dt.Xcode IDEIndexDisable
defaults write com.apple.dt.Xcode IDEIndexEnable 1 


回答27:

Go to the project folder and delete derived data folder

if you cant find the derived data, go to finder and go to

 ~/Library/Developer/XCode/DerivedData/"project"

(replace "project" name with project name)



回答28:

I just restart Xcode and then it works.



回答29:

Okay guys saw almost all top answers and none worked for me.

So what worked for me is the following:

  1. Copy the Derived Data address from your Xcode project. This can be done using the following:

Xcode -> Preferences -> Location Tab -> Derived Data

  1. Close Xcode

  2. Now go to the derived data location and delete the folder of your project there.

Now open Xcode and voila!



回答30:

In my case, it was because the Xcode indexing process had stopped running. Rebooting my Mac fixed it.