Xcode,找不到我创建的类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12123171/
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
Xcode, can't find my class which I had created
提问by John Brunner
I'm playing arround with Xcode (for iOS) and added a View Controller to my Storyboard. Now I've created a Class (File -> New File -> Objective-c Class) and made that a subclass of UIViewController. Now the .h and .m files are generated and listed on the left side in Xcode, but when I want to change the "custom class" of my added View Controller there is nowhere my class which I had generated. Am I doing something wrong?
我正在使用 Xcode(适用于 iOS)并在我的故事板中添加了一个视图控制器。现在我已经创建了一个类(文件 -> 新文件 -> Objective-c 类)并将其作为 UIViewController 的子类。现在 .h 和 .m 文件生成并列在 Xcode 的左侧,但是当我想更改添加的视图控制器的“自定义类”时,我生成的类无处可去。难道我做错了什么?
Thanks in advance.
提前致谢。
回答by mad pig
I've had the same problem. Quitting and opening Xcode will make the Class show up in the list.
我遇到了同样的问题。退出并打开 Xcode 将使 Class 显示在列表中。
edit: I've also recently found pasting the Class name will work in 5.02 Xcode.
编辑:我最近还发现粘贴类名称可以在 5.02 Xcode 中使用。
回答by Eduardo Leal
I had the same problem. But I discovered that I was clicking inside the "window of storyboard" and was selecting a view, so with no viewController related to. My solution was: to click inside the owner, or the viewController from the left list, and then change the custom class.
我有同样的问题。但是我发现我在“故事板窗口”内单击并选择了一个视图,因此没有与 viewController 相关。我的解决方案是:单击所有者内部或左侧列表中的 viewController,然后更改自定义类。
回答by Saad Chaudhry
There Are multiple ways....
有多种方式......
1
1
Select project icon > TARGETS > Build Phases > Compile Sources Click the + button and add your *.m file
选择项目图标 > TARGETS > Build Phases > Compile Sources 单击 + 按钮并添加您的 *.m 文件
2
2
ANOTHER IS
2.1.save all my work; 2.2.just quit Xcode & load it again; 2.3.then I was able to insert the new outlet connection successfully.
另一个是
2.1.save all my work; 2.2.just quit Xcode & load it again; 2.3.then I was able to insert the new outlet connection successfully.
3
3
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 you project.
4
4
Simply Clean your Project then Build Again check or run.
只需清理您的项目,然后再次构建检查或运行。
回答by HeadNinja
I'm not sure what you mean by " but when I want to change the "custom class" of my added View Controller there is nowhere my class which I had generated ". It seems like you are trying to make the UIViewController in your storyboard to be of the same type of your custom UIViewController subclass.
我不确定你的意思是“但是当我想更改添加的视图控制器的“自定义类”时,我生成的类无处可去“。您似乎正在尝试使故事板中的 UIViewController 与您的自定义 UIViewController 子类具有相同的类型。
If that's the case, then select your UIViewController (make sure you're not selecting the UIView within that UIViewController)
如果是这种情况,请选择您的 UIViewController(确保您没有选择该 UIViewController 中的 UIView)
With the UIViewController selected, open the right hand view and open the Custom Class tab, then start typing in the name of your UIViewController subclass.
选择 UIViewController 后,打开右侧视图并打开自定义类选项卡,然后开始输入 UIViewController 子类的名称。
If that isn't working, then you need to ensure that the in the .h file you say:
如果这不起作用,那么您需要确保在 .h 文件中您说:
@interface MyCustomUIViewController : UIViewController
If it still isn't working, ensure that in storyboard you are selecting the UIViewController that you put down. If you are trying to fill in the Custom Class of a UIView with a UIViewController subclass, it shall not work!
如果它仍然不起作用,请确保在情节提要中选择了您放下的 UIViewController。如果您尝试使用 UIViewController 子类填充 UIView 的自定义类,它将不起作用!
If it all still doesn't work, try COMMAND+SHIFT+K, and COMMAND+B to Clean and Build! Good luck.
如果这一切仍然不起作用,请尝试使用 COMMAND+SHIFT+K 和 COMMAND+B 来清理和构建!祝你好运。
回答by dorian
Just a quick advice in case you are about to give up: Do check that the item you have in the storyboard is compatible with the custom class you created that you are trying to assign. For example, you cant choose a UIView based class if you have a UIImageView as a component in your storyboard. In that case, it simply wont appear in the dropdown list.
如果您即将放弃,请提供一个快速建议:请检查您在情节提要中的项目是否与您创建并尝试分配的自定义类兼容。例如,如果您的故事板中有 UIImageView 作为组件,则不能选择基于 UIView 的类。在这种情况下,它根本不会出现在下拉列表中。
回答by codepushr
You don't have to completely quit Xcode. Just close all your Storyboard tabs completely and reopen a new tab by double clicking on it.
您不必完全退出 Xcode。只需完全关闭所有 Storyboard 选项卡,然后双击它重新打开一个新选项卡。
回答by gbk
Solution for my situation - just close all other xCode windows (i got opened few projects at same time).
我的情况的解决方案 - 只需关闭所有其他 xCode 窗口(我同时打开了几个项目)。
Also sometimes help cleaning of project.
有时也有助于清理项目。