Storyboard uiviewcontroller, 'custom class' not showing in drop down

62,948

Solution 1

Two ways I found that solve the problem but they are work arounds:-

  1. Just type the view controllers name in the text field, or
  2. 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.

enter image description here enter image description here enter image description here

Solution 3

I would try the following:

  1. Check that the file implementing the class is part of the build phases (check under target > build phases)
  2. Add the .m file to build phases (if it isn't already).
  3. Restart Xcode.

Solution 4

You can fix this by editing the XML of your Storyboard.

  1. 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 attribute customClass="MyController".

  2. Save the storyboard.

  3. 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
Share:
62,948
1dayitwillmake
Author by

1dayitwillmake

I am a programmer living in the Bay Area. I enjoy making visual things with code, and learning.

Updated on December 24, 2021

Comments

  • 1dayitwillmake
    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
    1dayitwillmake over 11 years
    Yeah 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
    tiguero over 11 years
    Oh so it is working if you are typing the name of your class manually?
  • tiguero
    tiguero over 11 years
    It might just be a bug from XCode then. Did you try with some other custom class?
  • Joe
    Joe about 11 years
    this 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
    mikeborgh over 10 years
    Make sure your class is a inherits from UIViewController. @interface ClassName : UIViewController
  • arlomedia
    arlomedia over 7 years
    I 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 the UIViewController 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
    Chris Livdahl over 7 years
    I'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
    Can Poyrazoğlu about 7 years
    This! none of the others solved my problem, this one did.
  • Pete
    Pete almost 7 years
    Thanks, this fixed it for me!
  • user3741598
    user3741598 over 6 years
    In case anyone is following: I had the problem and can confirm @tiguero workaround is still working on iOS 9.0.1.
  • user1872384
    user1872384 over 5 years
    Closed the xcode project and it works. Bug still exist in Xcode 10 =.=''
  • xdeleon
    xdeleon about 5 years
    Your 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
    Backrub32 about 5 years
    Well glad I did help! :) and thanks for commenting your case of the problem!
  • François Legras
    François Legras over 4 years
    Thank you so much! Same problem here, did not know about the folder thing.
  • Emil
    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.