Unknown Class **** in Interface Builder file

佐手、 提交于 2019-12-10 12:34:28

问题


I added a UIView xib file using the root class of MyView.

I created it in the wrong place and so moved it in the project. Same project just a different folder/group.

I then had a problem when running saying...

Unknown Class MyView in Interface Builder file

I couldn't work out what was wrong so I have now deleted the files both from the project and from the directory.

I've done a search using SublimeText2 for the string "MyView" and it doesn't exist anywhere in the project.

I've reset the simulator, cleaned the project and the build folder and deleted derived data.

Still getting the same error.

Any ideas what I can do now?


回答1:


Sometimes IBuilder missed customModule="AppName" customModuleProvider="target"

To fix it, open storyboard as source code and replace this line:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
sceneMemberID="viewController">

to this:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
 customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">



回答2:


Go to View -> Utilities Goto File Inspector of .m file

Open the Target Membership section and make sure that your target is selected for this .m-file




回答3:


If you have multiple targets in your Xcode project, make sure that the class the was mentioned in the error file is compiled for the target you're testing with as well.




回答4:


appcode is very stubborn in keeping the old xib cached somewhere, and if you have the cached xib and it has the same name that your controller it will try to load it on start.

what I do after deleting a .xib:

  1. delete app from the device
  2. clean build folder in app code
  3. invalidate caches and restart, kill appcode before it starts
  4. delete derived data in xcode
  5. start appcode

step 4 shouldn't be necessary, but my feeling is that without it I am still seeing the deleted .xib




回答5:


This happened to me when I renamed the custom view class, and the module (in the identity inspector when the view is selected) was blank. It remained blank because Xcode didn't autocomplete the custom class name, hence it left the module blank. All I had to do was re-enter the class name after a build, and then it autocompleted, and selected to appropriate module (Current - Target)




回答6:


In my case, I solved by checking "Inherit Module From Target" option in Identity Inspector.




回答7:


OK, so I deleted all references to the class causing the problem but still nothing.

However, I also had a UIViewController subclass called MyViewController. This wasn't being loaded in any IB file so I don't know how it was causing the problem.

I changed the name to MyOtherViewController.

Build - Run - works.

I don't know how or why but it works now.




回答8:


I had the same issue when I had multiple class declarations in one file. What I did is I declared a UITableViewCell subclass in one of my view controllers, and forgot to put the UITableViewCell subclass' @implementation in the view controller's .m file.




回答9:


As my experience, All solutions above had not worked out. Then I had to re-input the custom class in all strayed Xibs. As an amazing result, it just succeeded and what I had done reconnected the lost connection between @interface and IB. Hope to be useful.



来源:https://stackoverflow.com/questions/19401783/unknown-class-in-interface-builder-file

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