ios “找不到名为 ViewController 的类的任何信息”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17735182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Could not find any information for class named ViewController"
提问by user2597451
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:
自从我开始使用 Xcode (4.6.3) 以来,这个错误一直让我发疯。每当我尝试将 Storyboard 项目链接到我的代码时,我都会收到错误消息:
Could not find any information for class named ViewController.
找不到名为 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.
- 删除委托数据。
- 删除和重新添加类。
- 重新启动Xcode。
- 重新安装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?
无论类是什么,我都无法在我的任何项目中按住 ctrl-drag 来创建连接。全新的模板应用程序也会出现同样的问题。如果我手动输入代码然后按住ctrl-drag,我可以建立一个工作连接,但我不能自动添加它。到目前为止,我在互联网上找不到任何帮助。任何指针?
回答by Chris Harrison
What solved this issue for me was actually deleting the class from the project.
为我解决这个问题的实际上是从项目中删除了这个类。
Steps:
脚步:
- In the project file explorer (left panel) find the class and right click -> Delete
- Remove reference(do not move to trash as you will lose the class for good)
- Right click on the folder that contained the class -> Add files to ...
- Find the class you just deleted in the file system
- 在项目文件资源管理器(左侧面板)中找到该类并右键单击 -> 删除
- 删除参考(不要移到垃圾箱,因为您将永远失去课程)
- 右键单击包含该类的文件夹 -> 将文件添加到 ...
- 在文件系统中找到刚刚删除的类
This seems to force Xcode to link the class back into the storyboard.
这似乎迫使 Xcode 将类链接回故事板。
Note: for me the following did notwork:
注:我下面也没有工作:
- Closing Xcode
- Cleaning the project
- Deleting the class name from the storyboard and re-entering it
- 关闭Xcode
- 清理项目
- 从故事板中删除班级名称并重新输入
I think this is a bug on Apple's part
我认为这是苹果方面的一个错误
回答by Andrew Robinson
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 codeto 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...
我所做的是在我的班级中手动输入一个插座,例如:@IBOutlet weak var someView: UIView!
,然后从代码拖动到 IB 或故事板中的视图。在此之后,我可以从 IB / Storyboard 拖到我的班级以建立联系,助理编辑在“自动”中识别班级,等等......
Works every time.
每次都有效。
回答by Ruud Visser
回答by MRizwan33
Sometime Xcode does due to VC not referencing class file. The simple solution for this is:
有时 Xcode 是由于 VC 没有引用类文件。对此的简单解决方案是:
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!!!
这将在 @IBOutlet 之前创建一个空链接符号,在助理编辑器中打开您的项目,然后单击链接符号并将其拖入您要连接的视图(我已与 TableView 连接)。就是这样。享受快乐编码!!!
回答by Jesus Rodriguez
I just had this problem on April 2017 with Xcode 8
我刚刚在 2017 年 4 月使用 Xcode 8 遇到了这个问题
Simply creating an outlet through code and compiling fixed it. eg:
只需通过代码创建一个插座并编译即可修复它。例如:
@IBOutlet weak var containerViewHeight: NSLayoutConstraint!
You got to love Xcode…
你必须喜欢 Xcode…
Edit: Still happening on Xcode 9
编辑:仍在 Xcode 9 上发生
回答by Amr Angry
the following steps works for me hope that works for you also
以下步骤对我有用,希望对你也有用
1- You need to reopen you project after closing Xcode.
1- 您需要在关闭 Xcode 后重新打开您的项目。
2- Wait for indexing project files
2-等待索引项目文件
3- Check if it work or not
3-检查它是否有效
4- If still not working follow step 5, if not happy for you :)
4- 如果仍然无法正常工作,请按照第 5 步操作,如果对您不满意 :)
5- Clean and Build your project target
5-清理并构建您的项目目标
回答by gmogames
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!
- 清理构建文件夹和项目。
- 打开项目(窗口 -> 项目)
- 在列表中找到您的项目并删除派生数据
- 关闭 Xcode
- 重新启动计算机(不选择重新打开打开的窗口)
- 运行 Xcode
- 工作!
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.
我所有的视图控制器都没有被识别,所以删除所有文件并重新添加不是一个选项,因为这是一个大项目。
回答by Joe149
For me, the following worked:
对我来说,以下工作:
Do a 'clean' and a 'clean build folder' (press 'option' on the Product menu to get the 'clean build folder' command
Stop Xcode
In terminal, go to the derived data folder:
(/Users//Library/Developer/Xcode/DerivedData)
执行“清理”和“清理构建文件夹”(按产品菜单上的“选项”以获取“清理构建文件夹”命令
停止Xcode
在终端中,转到派生数据文件夹:
(/Users//Library/Developer/Xcode/DerivedData)
Delete the derived data dir for your project.
删除项目的派生数据目录。
Wave dead chicken in the air
Start Xcode
在空中挥舞死鸡
启动Xcode
回答by yndolok
I had to do a combination of a couple of the answers so far:
到目前为止,我必须结合几个答案:
- 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)
(点击storyboard中视图控制器左上角的黄色按钮->进入身份检查器(option + command + 3)->删除顶部的自定义类名)
- Remove the reference to the view controller file.
- 删除对视图控制器文件的引用。
(Right-click the file -> delete -> remove reference)
(右击文件-> 删除-> 删除引用)
- Add the view controller file back to the project.
- 将视图控制器文件添加回项目。
(Right click the folder where the file was -> "Add file to [project]")
(右键单击文件所在的文件夹->“将文件添加到[项目]”)
- Add the custom class name back to the storyboard.
- 将自定义类名添加回故事板。
回答by programmer
This worked for me:
这对我有用:
- Perform 'Clean build folder'
(press and hold the 'option' key and go to the "Product" menu to access it. - Perform a simple "Clean" (CMD-SHIFT-K) from the "Product" menu.
- Buildthe project to let Xcode compile the files. Also, let it index files if necessary.
- 执行“清理构建文件夹”
(按住“选项”键并转到“产品”菜单以访问它。 - 从“产品”菜单执行简单的“清洁”(CMD-SHIFT-K) 。
- 构建项目以让 Xcode 编译文件。此外,如有必要,让它索引文件。
On a side note, I am not sure if this helped but I also deleted the Derived databefore performing the above steps (Xcode preferences > Locations)
附带说明一下,我不确定这是否有帮助,但在执行上述步骤之前我也删除了派生数据(Xcode 首选项 > 位置)