Unknown class in interface builder - ios

I know that there are a lot of questions on this subject but I've tried most of them to try and figure it out with no success.
the problem:
at first I couldn't add my class from the assistant editor cause the custom class didn't pick it up.
I made sure the calls inherits from uiviewcontroller
I made sure the class is added to the target
I tried to remove the class file and re-add it back
finally I've added the class through the storyboard xml and it appeared in the custom class
Now I'm trying to connect my buttons, views etc to its outlets. It seems like they are connected but when running the app and opening that view controller the app crashes and the debugger prints:
"Unknown class xxx in Interface Builder file."
and than
"this class is not key value coding-compliant for the key btnMenu."
I've checked:
That connection inspector is properly set (no error in the outlets there)
Tried to delete derived data
Clean project
Re-install the app
I even tried restarting my mac and of course no success.
can anyone shad some light here?
thanks.

I just had this happen with a UIViewController subclass (with Xcode 9 beta 2 & Swift 4) and the solution was to tick 'Inherit from Target' where I set the Custom Class in IB.
If your view happens to be in a .bundle file (such as for a framework/static library) that gets copied to a different target, you'll want to set an explicit module target for each xib/storyboard class rather than having it inherit from the target that's hosting it.

For me the problem was that the class was not part of the Target Membership. Just add the class to the target, and you should see it back on the interface builder. This Helped in my case.

After I checked the tick mark called "Inherit Module From Target" in Custom Class in View Controller Section, it works fine. Can Follow the image.
To find this >
Select your view controller yellow button > then click "Show Identity Inspector" > then checked the tick mark called "Inherit Module From Target"

What #Anthony Scott mentioned is true until you have Framework_A dependent on Framework_B and class is from Framework_B :) Then you need to deselect checkbox and provide Module which contains given class. Thanks for the question btw. I am using Commons framework for other frameworks and it helped me to realize this ;)
For those who develop custom Cocoa Touch Frameworks this can be helpful.

If you are trying to assign a class to a ViewController, please make sure the class you created is inheriting a UIViewController. The only reason that xCode won't recognize your class is where it is a different type of instance, let's say, may be a UITableViewController type.
Please check the inheritence of your class first.

I had this problem with a custom UIView I was testing, where the UIView was in a framework. I had created a simple app, created a UIView in the Storyboard's default ViewController and set its class to MyCustomView. I always got the "Unknown class in interface builder" error when the app launched. I was importing my framework, and I checked in the built product that the framework was there.
The problem was that my test app code never actually used the framework. Even though the Storyboard referenced it, I guess it never got loaded. When I added a [MyCustomView load]; into the test app code, it all worked.

For those who encounter this problem but with a system class like PKCanvasView or ARView, in a storyboard.
After you've set view's Custom Class to any of those system classes, make sure the Module is set to None. Next go to target's Link Binary with Libraries in Build Phases and manually link the framework which contains that class. One last step is to do a clean and remove derived data (it's critical otherwise the problem won't float away).

ok so i dont know how and why, but, i did (AGAIN) what i already tried before which is:
deleting the class
creating the same class with new name
removed the scene and recreated it in the storyboard
connected it all (in the same usual way!!!)
now it seems that Xcode knows my class....
i still don't know what was the problem but i guess it has something to do with the linker.

I ran into this error because I accidentally saved my class file to the Base.lproj folder when I created it.
I fixed the error by right-clicking the file in the Project Navigator and deleting the reference to it. I then moved the file through Finder to the correct folder. Then I right-clicked the main group in the Project Navigator and clicked Add Files to "GroupName"... and selected the class and clicked the Add button.
After that the error went away.

Check the name of your class. Make sure that it corresponds to the class to which you have assigned your ViewController in the property inspector.

You need to instantiate the view controller with the custom class. Without that you might have the error.
self.storyboard!.instantiateViewController(withIdentifier: "namePage") as! EmailAndPassword

none of this helped. My problem was I created custom storyboards and added custom classes. But I forgot to take of the initial view controller arrow from auto-generated main storyboard and changed the initial storyboard to my custom storyboard which fixed it for me.

I found the problem for me was that the UIViewController that I was pointing to did not have a ViewController.swift file attached to its "Custom Class" parameter!

Related

Not Showing EDStarRating in Custom class dropdown list?

I have integrated EDStarRating in my application. it is working fine on one viewcontroller. but strange problem is it is not working on another view controller.
I have searched almost all google quection releted to this problem but nothing is working for me.
I have deleted EDStarRating from my application added again. then also it is not showing in custom class drop down list. I have checked in build phases, it is there.
Another strange thing is it is not showing in custom class drop down but it is working fine on one view controller there is no issue.
same thing trying to apply on another view controller it is giving error.
Unknown class _MyApplication14MYEDStarRating in Interface Builder file.
Appreciate for help
Are you writing both the view controller that it works on and the one it doesn't in Swift? That you're getting a module-mangled class name for an Objective-C class suggests that you're running into a form of this bug:
Objective-C class is interpreted as Swift class in Interface Builder
Actual Results:
Outlet will refer to a Swift class - Name is mangled with App module name, so it can't resolve to an instance of that class.
The result is the subview having the original class in interface builder. If it was dragged from a 'View', it will be an instance of UIView, if it was dragged from 'ImageView', it will be an instance of UIImageView.
What I'd suggest is taking a look at the source of your storyboard (right click, Open As > Source Code) and manually copying the customClass from the instance that works to the instance that doesn't. Assuming they are different, and Interface Builder just got confused. If they're not different ... then there's some more subtle Swift/Objective-C bridging problem. Probably just rewriting EDStarRating in Swift would be quicker than figuring it out, really.

Xcode 6: can't connect any IBOutlet to ViewController

After upgrading to Xcode 6, I opened an old project (that contains a subproject, so it has many targets)
and I noticed that no link from my Storyboard ViewContoller to the relative Objects works.
For example I have a ViewController with a TableView inside and now I cant do can't do anyhing with it because the connection is missing, I can't even redefine a new IBOutlet in the VC because the arrow in the storyboard from the VC won't connect to anything.
To be more clear:
The class is defined in the Custom Class section, so I can't find the problem
What should I do?
Btw I'm using obj-c not swift, I found some related answer but all about swift.
You can also see that the link between the parent view and the custom class is broken (not visible anymore) which is a huge problem.
I had the exact same issue with the app i'm working on actually, updating XCode from 5.xxx to 6.1. The workaround that worked for me was to remove the reference of every view controller and re-add them to the project...
To everyone facing that issue, here's the (annoying) trick :
Step 1 : select both .h and .m view controller files
Step 2 : remove the reference of those files
Step 3 : re-add the files to your project tree
Step 4 : open the storyboard, eventually re-build the project and smile
I can understand those things could be reaaally annoying, but it worked for me... Hope it will help someone else !
In your storyboard hierarchy select the View Controller,
In the right pane Custom Class section Class, select the drop down and your desired view controller.
I've experienced similar behaviour in Xcode 6.1.1 when trying to add the first outlet to a new view.
Tried removing the references and adding the files again as suggested above with no success.
What I did find worked was writing the first property on the new view by hand. I just popped in:
#property NSString *temp;
I could then attach my outlets in the normal way. Just delete the temporary property once you've added your first outlet.
Hope this helps.
It seems typing the outlet first (swift):
#IBOutlet weak var someViewOutlet: UIView!
and then dragging from IB the outlet to the far right type in the above code works.
Restarting Xcode resolves the issue (sometimes). Using Xcode 6.1
Maybe I can help
In my case the problem was that the viewController.swift file was not connected to the StoryBoard. The solution is to click in the Upper border of the view on the storyboard beside the 3 icons (View Controller, First Responder and Exit)...now look over in the Utility Area choose Identity Inspector, and in "Custom Class" choose the custom view controller.
Hope this helps. Xcode is hard!!
Here's the proper solution i believe.
If you renamed the controller in code, you need to update the .xib file.
I could not find a way to do it in the interface builder, so do this:
Open the .xib file with a text editor: right click the file > open as > source code
In the <objects> node find the <placeholder> node with the property placeholderIdentifier="IBFilesOwner" and replace the value in customClass="MyOldControllerName" with your new controller name: customClass="MyNewControllerName"
And all your IBOutlets will work as normal again.
Thanks to everyone who commented.
It is a bug of Xcode 6 / 6.0.1. Downloaded and installed the 6.1 version and the problem disappeared.
Maybe try to delete the outlet from the menu in the storyboard (in your screenshot) and drag it again of the element.
Okay, let's check iff it is the lack of a module name.
In your storyboard ViewController, type in the name of module. (the project name)
2.Clcick outside in another field. When you go back to the module field it may say none, but now there will be a dropdown menu entry for your project name.
Select your project name and see if everything is good.
If there are still issues I will post photos.
Seems to be a workspace issue. Try to remove project form a workspace and add it again. It helped in my case.
I had this, affected all projects on my machine, swift and objective c and drove me mad for ages. Finally also noticed that I could not use the refractor to rename classes either.
The fix for me was:
Close xcode
Delete ~/Library/Developer/Xcode/DerivedData (just doing this on its own did not work!!)
Delete all user data for all my projects using the following from the directory that contains all my projects e.g. /src (be careful with this command!):
find . -name 'xcuserdata' -exec rm -rf {} \;
If you want to do it by hand just do the following for all your projects
Delete .xcodeproj/project.xcworkspace/xcuserdata
Delete .xcodeproj/xcuserdata/.xcuserdatad
Get Spotlight to re-index the drive all my projects were on (not sure if this was required
Re-boot machine
Everything sprang back into life !
I was having this same issue.
It turns out I renamed my view controller class and file name. In storyboard, I had the stale value in the right pane, Custom Class -> Class. So the IBOutlets were not aligning because there were none in the missing class, which is where it was expecting to find the defined outlets.
Filling in the correct class name of the View Controller in the Custom Class field in the right pane fixed my issue.
XCode needs to be more verbose if you have a bad class name in the Custom Class fields.
no one solution fixed my same problem...
But i have solved by:
close xcode
renaming the folder of the project
open xcode
and then the outlets will be back again
I hope that this solution is the right one for the people who have the same problem
In Xcode 6.3 I needed to close Xcode and restart the Mac. Restarting Xcode alone didn't do it for me.
I've had 6.3 for a long time and my problem was with new projects I was creating to test some things. Definitely not an upgrade issue this time.
I have Xcode 6.3 and saw similar issue. Finally few edits in .h file resolved my issue. If your interface has IBOutlet defined as
#interface NavigationViewController :UIViewController
{
IBOutlet UILabel *lblName;
}
change this to and in .m file add #synthesize lblName;
#interface NavigationViewController :UIViewController
{
__weak UILabel *lblName;
}
#property (nonatomic, weak) IBOutlet UILabel *lblName;
I was having this same problem, with no view outlet available to link to. The only way I was able to fix it was to change the owner class of the XIB file to "UIViewController," make the link, and then change it back to my intended custom view controller class. The link stayed and all was well.

"loaded the "XXX" nib but the view outlet was not set." - again

Firstly I have inspected all of the other questions on this topic: the answers provided seem to be:
make sure you set the file's owner to your custom view controller class (which I have done)
make sure you have a referencing outlet from the view to the file's owner (which I have)
My code is compiled to a static library, and I export the .a file and xib file.
My example app that uses it includes the xib in its bundle ("copy bundle resources" in build phase)
In my library code I have a function in a separate UIViewContoller subclass to create the view controller from the nib:
- (void) presentCustomController
{
self.vCtrl = [[CustomController alloc] initWithNibName:#"CustomController" bundle:nil];
...
}
When I run the example app, I inspect the _view member of self.vCtrl, and it is 0x0000, and of course this is what causes the exception in the posting title.
My understanding was that the view to which that member points was 'auto generated' from the xib file, and it's children were the controls that I have put in it (buttons etc).
What part of my understanding has fallen down? Is the problem related to the fact that it is in a static library?
Thanks for any help.
If you are 100% that you connected your View to the File's Owner then I suggest you do the following:
Clean the project (cmd+shift+K) or Clean Build Folder if you prefer (cmd+shift+alt+K)
Quit Xcode
Restart Xcode
That should fix it hopefully.
Do you have multiple targets?
make sure you set the file's owner to your custom view controller class (which I have done)
I have come across a similar issue where I thought that I was setting the file's owner's custom class, however, IB was not actually setting it. Open the XIB as its raw xml and search for the custom class name.
For me it was because the .m of the view controller was not included for my specific target. To fix this check all the boxes in the target membership pane.

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

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?
Two ways I found that solve the problem but they are work arounds:-
Just type the view controllers name in the text field, or
close the project and then reopen it and in the project initialization it places the file on the list.
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.
I would try the following:
Check that the file implementing the class is part of the build phases (check under target > build phases)
Add the .m file to build phases (if it isn't already).
Restart Xcode.
You can fix this by editing the XML of your Storyboard.
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".
Save the storyboard.
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.
Make sure your class inherits from UIViewController.
#interface ClassName : UIViewController
In Xcode 8, a few of my classes had the wrong path (case sensitive) specified for their file locations.
MyProject/mysubdirectory/MyViewController.xib (.m, .h)
vs:
MyProject/MySubdirectory/MyViewController.xib (.m, .h)
Really not sure how it ended up in that state, but my project exhibited the exact same behavior as above (no outlets/actions displaying in IB), and fixing that path fixed the problem.
I fixed this two different ways. One way was by I opened the .pbxproj file and fixing the case sensitive issue manually. The other way that worked was by tapping the folder icon under the Identity and Type section of the File Inspector tab of the file, and re-selecting the file there.
Click on a different view controller in the storyboard, then click on it's custom class pulldown to confirm the new class is listed, but don't select it. Click back on the new view controller you made and you should see it now listed in its custom class pulldown menu. odd, eh? just forces a refresh I think.
I had been having the same issues as described in this problem. However, none of the suggested answers fixed it for me. My project compiled OK without warnings or errors, but, in the .h file there were no 'outlet' indicators to indicate that my outlets had been linked to storyboard elements.
Additionally, attempts to create new outlets in my code, by right-click and dragging into my header file, were not recognising my header source as a potential target for this operation. And furthermore, my Class did not make an appearance in the Custom-Class dropdown for the ViewController's property inspector panel.
And yet, the project compiled OK.
Closer examination showed that I had defined my own class in the following manner...
#interface KJBMainDataViewTrackConMk2<UIScrollViewDelegate> : UIViewController
which apparently compiles nicely.
But, if this is changed to the following, (moving the protocols to the end)...
#interface KJBMainDataViewTrackConMk2 : UIViewController<UIScrollViewDelegate>
Then everything springs to life. All outlets are suddenly indicated as being 'connected' with a storyboard element. And right-click dragging starts to work again, and my custom class appears in the custom-class drop-down in the property inspector panel for the storyboard ViewController!
Other answers here probably represent the most likely causes of this condition, but, I felt it worth mentioning at least this one other potential cause.
I had the same problem, but none of the other solutions worked for me. The issue for me was that I had a Mac and iOS target, both with their own versions of the same view controller. For example, I had a .h/.m pair of files named FooViewController for Mac and another .h/.m pair of files named FooViewController for iOS. Each pair was properly included with their respective targets, but for some reason Xcode does not like it and my view controller would not show up in the Custom Class dropdown in the view controller in the storyboard. I ended up renaming my class in the iOS view controller and it immediately showed up in the dropdown.
In my case, I drag a new TableViewController object to the storyboard, but I add a new file which's subclass is "UIViewController".... Then, I add a file which's subclass is "UITableViewController", problem solved!!
For those of you who are still having this problem after trying all the way around is probably because you clicked the View instead of ViewController.
You have to choose the file when ViewController is clicked.
This solved my problem.
I happened to come across this problem, and had no luck after trying the previous suggestions. Finally I found the reason is the header file's type is set to C++ header. After changing it to C header (like all the other header files), the class appears in the drop list. Don't know why though... Possibly helpful for others so I post it here.
Storyboard is looking for the custom class but physically its no there and its not displaying the custom class name in the list and also not displaying the outlets . Following solution perfectly worked for me.
Just copy your code some where else.(Lets say on desktop)
Open your existing code.
Delete the custom class file.(Move to trash)
Now add files from copied project folder (From desktop)
Don't forget to check "Copy if needed" check box
Open the story board and bingo you will get your custom class files in dropdown
be sure initially not adding the CustomViewController to any group or folder. place it in the root of your app.
none of the above(or below :) helped me. though I found that
after adding new viewcontroller to storyboard (just by dragging it in)
and adding my class by File\New\File\Objective-C Class, give it a name, no XIB, Next, Create
if I select my viewcontroller in storyboard and try to assign my class to it - my class is not there
BUT
if I click on a view that is in the viewcontroller itself then click on a class dropdown menu in Custom Class
AND THEN
select viewcontroller (click on a bar below the viewcontroller) and now again click on a class dropdown in Custom Class my newly added class magically shows up.
weird, must be a bug with refreshing. Xcode Version 5.1 (5B130a)
Make sure you select View Controller to which you want to attach your class. The easy way is open Document Outline and choose your view controller (When you tap on it form the Storyboard sometimes it simply doesn't choose the object you meant).
for my case, somehow bundle resources got deleted, so I added back and worked!
Build Phases -> Add Build Phase -> Copy Bundle Resources
find your file
Then drag and drop your file there
Then make sure your target membership is checked.
In my case, I selected the wrong UI.. so I deleted the class file and created a new one and selected the correct parent class
I had to restart XCode 7.3 (7D175)
What worked for me was, click on the file in the Project Navigator, then, in the File Inspector under "Identity and Type" beneath the "Location" dropdown box, click on the little folder icon and then select the file in the popup window.
Try to clean your project, and also restart your Mac. One peculiar thing that I did was change all the Custom Classes names and build the project again. It worked!
For macOS projects, creating a new class generated a class inheriting from NSObject instead on NSViewController.
Change from
import Cocoa
class AppsViewController: NSObject {
}
to
import Cocoa
class AppsViewController: NSViewController {
}
I was fairly frustrated with this issue as none of the answers above had solved my problem.
In my case: I was in the middle of working on swift view controller file and was making active changes (such as creating a custom collection cell class). I had not finished the code block and left it open like so :
class tableViewCell: UITableViewCell {
}
class collectionCell:
class viewController: UIViewController {
override func viewDidLoad(){
super.viewDidload()
}
}
Note the incomplete code block 'collectionCell2'
This was enough for xcode to not recognize my viewController file as such.
Once I completed this block the file reappeared in my xcode as an option.
Very silly and simple.
Make sure the view controller is matching with the same Type in the storyboard .
In my case swift file name was different then swift class name i.e
file name was ViewControllerTest.swift
and class name was ViewController.swift
after changing both to common name solved my problem
Restart Xcode after above changes
Make sure the class name of the ViewController is the name that you want. i.e.
class MyCustomNameViewController: UIViewController {
.
.
}
Changing just the filename is not enough.

Using iCarousel framework on storyboards

Has anyone tried to implement iCarousel with storyboards? I have an existing project, but not sure if this will work with Storyboards or not. Has anyone done this successfully or provide any directions on what do I need to implement this in a Storyboard project?
I've got to admit, I can't work out why Storyboards are causing an issue for so many people using iCarousel, but I've now included a Storyboard example in the project that demonstrates how to set it up correctly.
https://github.com/nicklockwood/iCarousel/tree/master/Examples/Storyboard%20Demo
FWIW, the view controller code for this example is identical to the Basic iOS demo.
Yes, it works with storyboards.
It works exactly the same way as before iOS 5 Storyboards.
You can create a view in your storyboard and set its class property to be "iCarousel".
Then connect iCarousel delegate and dataSource properties to point to your view controller. (don't forget that your view controller must implement iCarouselDataSource and iCarouselDelegate protocols). You can create an outlet for your iCarousel view too.
Thats all for you to access and to control your iCarousel using Storyboards.
Hope it helps,
hbobenicio.
Check that iCarousel.m is in the compile sources list for your app target. Project > App Target > Build Phases > Compile Sources in xCode 4.6.1.
So, another problem is, that if a view-class was changed to iCarousel and command-b is set, after compiling the alert "Unknown class iCarousel in Interface Builder file." comes.
No, no, iCarousel and Storyboard isn't a good idea.
And the solution:
Make a new Class in your Xcode-Project, name it "iCarousel". Via drag & drop put the Code from the original classfiles in there.
After that, it will work'S well.
I found a solution.
Don't copy the class iCarousel in the project-folder by adding them.
Just reference to them. Then it works.
I was having some issues but I just hadn't set the iCarousel.m file's Target Membership to the right thing when I dragged it in.
That is wrong.
I've try to implement iCarousell in a Storyboard-Project and always get delegate and datasource errors. I think it only works with separated xib.
Always: this class is not key value coding-compliant for the key dataSource.'

Resources