Storyboard uiviewcontroller, 'custom class' not showing in drop down
Solution 1
Two ways I found that solve the problem but they are work arounds:-
- Just type the view controllers name in the text field, or
- close the project and then reopen it and in the project initialization it places the file on the list.
Solution 2
If you still have your problem or for those who could have the same problem:
Make sure to select on your storyboard your "ViewController" instead of your "View" (which is automatically selected when you click on the view in the storyboard). The difference between those two is that when the view controller is selected, a blue rectangle pop up around your app. To be sure to select the view controller, open the document outline and select it directly in your storyboard hierarchy.
Solution 3
I would try the following:
- Check that the file implementing the class is part of the build phases (check under target > build phases)
- Add the
.m
file to build phases (if it isn't already). - Restart Xcode.
Solution 4
You can fix this by editing the XML of your Storyboard.
Right-click your
My.storyboard
entry in the Project Navigator panel and select the Open As->SourceCode menu choice. Find your view controller entry in the XML, and add the attributecustomClass="MyController"
.Save the storyboard.
Right-click your
My.storyboard
entry in the Project Navigator panel again, and select the Open As->Interface Builder - Storyboard menu choice.
The custom class entry will now contain your MyController
class name.
Solution 5
Make sure your class inherits from UIViewController.
@interface ClassName : UIViewController
1dayitwillmake
I am a programmer living in the Bay Area. I enjoy making visual things with code, and learning.
Updated on December 24, 2021Comments
-
1dayitwillmake over 2 years
I have a UIViewController I created in my apps storyboard, as well as a custom UIViewController subclass which I added to the project (and is correctly in the compile phase for my target). However when I go to set the 'Custom Class' property on the view-controller in Storyboard my custom class does not show up on the list.
- Checked that the class is part of my app's target, not tests'
- Double checked that it is correctly a subclass of UIViewController
- Compiled program just to make sure xcode was working with latest information
- Restarted xcode
What would cause my class to not show up in the 'Custom Class' drop down?
-
1dayitwillmake over 11 yearsYeah that was the first thing I checked, it's there. In fact, my NSLog gets called in viewDidLoad when I type in the class manually into the field. It's really annoying
-
tiguero over 11 yearsOh so it is working if you are typing the name of your class manually?
-
tiguero over 11 yearsIt might just be a bug from XCode then. Did you try with some other custom class?
-
Joe about 11 yearsthis doesnt work for me. I tried in 4.3.3 and 4.6.2 In a project I developed in earlier than 4.2 now loses the custom class!! Machine setting?? When I create a new project it is fine until I add a toolbar button or item to toolbar then it is gone no matter what!
-
mikeborgh over 10 yearsMake sure your class is a inherits from UIViewController. @interface ClassName : UIViewController
-
arlomedia over 7 yearsI had the same problem when adding a watch app extension to an iOS app and creating
WKInterfaceController
classes in the watch target with the same names as theUIViewController
classes in the iOS target. The Class menu in IB wasn't showing a watch class if it had the same name as a iOS class. And if I manually entered the class name, IB would only show the outlets for the iOS class. Is there a way to specify a class from a particular target? I had to prefix the names my watch interface classes and I would prefer to avoid that clutter. -
Chris Livdahl over 7 yearsI'll need to revisit this issue. In Interface Builder, there is a dropdown to select the target underneath the class dropdown, but I'll need to experiment and see if it works. I don't know if this target dropdown is a new feature.
-
Can Poyrazoğlu about 7 yearsThis! none of the others solved my problem, this one did.
-
Pete almost 7 yearsThanks, this fixed it for me!
-
user3741598 over 6 yearsIn case anyone is following: I had the problem and can confirm @tiguero workaround is still working on iOS 9.0.1.
-
user1872384 over 5 yearsClosed the xcode project and it works. Bug still exist in Xcode 10 =.=''
-
xdeleon about 5 yearsYour answer wasn't correct for me but put me on the right track. The problem is that I had a scene in Interface Builder that was a UITableViewController and I as trying to select a class where I had accidentally declared it as a UIViewController. Going to my class and changing what I inherited from to be a UITableViewController fixed my issue as was I was intentionally trying to use a UITableViewController but inheriting from the wrong base class when I declared the swift file.
-
Backrub32 about 5 yearsWell glad I did help! :) and thanks for commenting your case of the problem!
-
François Legras over 4 yearsThank you so much! Same problem here, did not know about the folder thing.
-
Emil over 3 years@mikeborgh thanks for the suggestion. In my scenario I was using UITableViewController, and my class inherited UIViewController so it wouldn't show up. Switched it to inherit UITableViewController and it worked.