24

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.

4
  • You don't "Change the class" of a storyboard, you set the Files Owner's class.
    – CodaFi
    Aug 25, 2012 at 15:18
  • thanks. but can't find the Files Owner button.. Aug 25, 2012 at 15:21
  • ok i don't know why, but now it works. now i can select my generated class! thanks Aug 25, 2012 at 15:25
  • To my experience, sometimes it does, sometimes it doesn't
    – Vincent
    Dec 23, 2012 at 14:37

7 Answers 7

44

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.

4
  • 2
    You would think Apple would fix that bug.
    – Kenny
    Aug 14, 2013 at 22:28
  • 2
    unbelievable that this is still needed in Xcode 5.0.2, but it is Dec 11, 2013 at 21:42
  • 2
    still have the issue in 6.4.. ridiculous
    – dorian
    Sep 3, 2015 at 13:24
  • 1
    Xcode 13.3 and here we are May 4, 2022 at 20:10
15

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.

1
  • This solved my problem. I didn't have to quit XCode, all I had to do was click the black bar under the scene. It selected the whole thing, and then I was able to assign it to my custom controller.
    – James Dunn
    Jan 14, 2014 at 16:25
14

There are multiple reasons and solutions....

#1

  • Select project icon in "Project Navigator".
  • Then go to your Target's Build Phases -> Compile Sources.
  • Finlly, click the + button, and add your *.m or *.swift file.

#2

In one case, the same file was added multiple times to project:

  • Remove all instance of the file.
  • Add file back to project (once).
  • Finally, select the file in "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:

right membership

#3

ANOTHER WAY IS

  • Save all my work;
  • Just quit Xcode & load it again;
  • Then I was able to insert the new outlet connection successfully.

#4

  • Close the project you are working on with.
  • Delete the【DerivedData】folder of you project.

    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.
  • Restart you project.

#5

  • Simply Clean your Project,
  • Then Build Again,
  • Finally, check and/or run.
0
3

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.

2

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.

0

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.

0

Solution for my situation - just close all other xCode windows (i got opened few projects at same time).

Also sometimes help cleaning of project.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.