Custom class not shown in the storyboard identity inspector

不打扰是莪最后的温柔 提交于 2021-02-07 14:31:00

问题


I created in my app a new class named EmpresasTableViewController, and in the storyboard I copied CategoriasViewController to EmpresasTableViewController, I just want to assign the class EmpresasTableViewController to EmpresasTableViewController in the storyboard, but the name EmpresasViewController doesn't appear in the Identity Inspector.

There are no errors after creating the class, but why is it not shown as a class in the storyboard Identity Inspector under Custom Class?, all other view controllers are shown.


回答1:


Firstly, all your files needs to be saved.

What you can try is:

Option 1. Close and reopen Xcode with your project.

Option 2. Clean your project and build it again.

Option 3. Force Xcode to do the indexing of your project once again:

Open the Organizer (Window > Organizer) and select the Projects mode. Select your project in the left-hand view and then click the Delete... button for the project's Derived Data.

This will delete the code sense index for the project and force Xcode to rebuild the index, which may fix the problem.




回答2:


None of the answers on the entire internet from Africa to Japan to Canada solved my issue. Zero. Tried all the hacks and tips and tricks known to the human race. This is because all of the answers pertain to projects with a single target.

Two hours, 50 gray hairs, and many tears later I realized it was because I created a watchOS WKInterfaceController class with the same name as an already existing iOS ViewController class. Xcode gives zero warning about this.




回答3:


The only thing which worked for me was to:

  1. Create a new group (folder) I called it Controller2
  2. Right click "Add file to ...
  3. Select all the class files
  4. Remove (reference) controller group
  5. Rename group controller2 to controller



回答4:


Just make sure that your view has the right inheritance class as the same storyboard view . if it is a table , make sure that you inherit from UIViewController class .. It solved my problem after i did everything . may it help




回答5:


You can edit the xib as text. The CustomClass attribute is on the view, change it manually here then switch back to the interface builder view.




回答6:


You can input your controller in Class column directly and manually.It's work.




回答7:


This is the answer:

Make sure you have UITableViewController selected and not UIViewController, that was my solution after looking for about 30min, I hope this helps

picture of my screen




回答8:


Another issue is if your Xcode project is stored on an external drive/SSD. I am experiencing this bug with Xcode 11.3.1. Simply move the project to the local Mac storage and open it. Interface builder will now work properly.

Sometimes it also helps to clean the project and rebuild. I've noticed that interface builder doesn't always update properly... must be another bug. (I miss the days when Xcode updates were reliable).




回答9:


If the custom class in question is not a subclass of the type of class you want to associate it, it wont auto populate in Identity Inspector. That is, for view controllers the custom class should be UIViewController. For table view cells it should be a subclass of UITableViewCell.




回答10:


For me the problem was that I've had two classes with the same name for Mac Os and iOs platforms, but with different targets. XCode doesn't seem to recognise that. Renaming classes for one of the platforms solved the problem for me. Also check and make sure that you've set the correct target for your custom class.



来源:https://stackoverflow.com/questions/21973474/custom-class-not-shown-in-the-storyboard-identity-inspector

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