Why aren't my custom classes appearing in the dropdown in Interface Builder?

回眸只為那壹抹淺笑 提交于 2019-12-20 06:13:42

问题


I am using Interface Builder and Storyboards to build my app. I am trying to connect my source code to my UIViewController in Storyboard, but none of my classes show up in the Custom Class dropdown menu. This is occurring in Xcode 11 beta 2 and Xcode 11 beta 4.

I've tried some solutions in this Stack Overflow answer, but they are not working. I've already done all of the following:

  • Relaunched Xcode
  • Deleted derived data
  • Reinstalled Xcode
  • Tried a different Storyboard
  • Recreated the UIViewController file
  • Made a new project (the problem even occurred there)
  • Typing the UIViewController name into the dropdown menu text field

None of the solutions worked and I have made sure that I was connected a UIViewController to the Storyboard not something else like a UIView. This is occurring with all of my UIViewControllers and UITableViewControllers.

(I wish I could show an image but I do not have enough reputation...)

I expected the UIViewControllers that I have created to appear in the custom class dropdown. I also surprised to find out that manually typing the view controller into the text field does not work. Instead, when I run the project, I just get this message in the console:

Unknown class ViewControllerName in Interface Builder file.


回答1:


It appears that your classes aren't added to the project target. Try this:

1) Make sure your classes are added to the right target membership on the Inspectors Panel on the right:

2) Make sure the class inherits the View Controller type:

class CustomViewController: UIViewController

3) Reload xCode and check if the class is enabled:



来源:https://stackoverflow.com/questions/57241318/why-arent-my-custom-classes-appearing-in-the-dropdown-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!