Reputation: 2872
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?
Thanks in advance.
Upvotes: 24
Views: 24874
Reputation: 1412
There are multiple reasons and solutions....
Project Navigator
".Build Phases
-> Compile Sources
.*.m
or *.swift
file.In one case, the same file was added multiple times to project:
Project Navigator
", and in the "File inspector
" on the right, look at the "Target Membership
" section. The app target (not the Test target) should be checked, similar to this:ANOTHER WAY IS
Said folder may be:
- Inside your project's folder,
- Or, inside ~/Library/Developer/XCode/DerivedData/(your project)/
- Or, somewhere else that was setup by you.
Upvotes: 15
Reputation: 847
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.
Upvotes: 2
Reputation: 11184
Solution for my situation - just close all other xCode windows (i got opened few projects at same time).
Also sometimes help cleaning of project.
Upvotes: 0
Reputation:
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.
Upvotes: 0
Reputation: 788
I've had the same problem. Quitting and opening Xcode will make the Class show up in the list.
edit: I've also recently found pasting the Class name will work in 5.02 Xcode.
Upvotes: 44
Reputation: 151
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.
Upvotes: 15
Reputation: 69
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.
If that's the case, then select your UIViewController (make sure you're not selecting the UIView within that UIViewController)
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.
If that isn't working, then you need to ensure that the in the .h file you say:
@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!
If it all still doesn't work, try COMMAND+SHIFT+K, and COMMAND+B to Clean and Build! Good luck.
Upvotes: 3