Unknown class <myClass> in Interface Builder file - ios

i get this error whenever i try to segue from one viewController to another. theres no code and ive been going through google pages and questions on here for hours and i cannot find a solution.

You experience this problem because:
You might have assigned a class to a View Controller in .storyboard file, which does not exist
You might have assigned a class to a View Controller in .storyboard before you created it and thus it failed to automatically set an appropriate Module.
You might have assigned class to a VC, which does not inherit from UIViewController.
Solution: Reassign VC class with help of the dropdown list OR manually chose "Current - Project Name" module from Module dropdown list. Make sure your custom class "extends" (inherits from) UIViewController.

Related

Subclassing a View Controller

I have a single view aplicaition on xcode with several view controllers and xib files in it. I am trying to subclass a xib file's view controller called ViewControllerPg62 as a sub class of a view controller called ViewController. How can i do this?
Thanks in advance
Why are you working with XIB files? You should be using Storyboards.
I had to go back to an old project using XIBs to see how they worked.
In an XIB you should see an entry called "Placeholders", and under that, an item called "File's Owner." That represents the object that owns and manages the views in the XIB. Select that, and then display the Identity Inspector. There will be an entry at the top "Custom Class" where you can change the class that manages this view controller.
Before changing that, I suggest you create the source file for your view controller ("ViewController.swift", in your case.) Then when you change the class of the owning object, the XIB will create an instance of your custom class when that XIB is invoked.
The approach is quite similar for Storyboards, although it's a little more coherent.

iOS Development: Is it necessary to change the class of the View Controller in the storyboard?

I am currently learning iOS development with Objective C. I am facing a couple of issues and I was wondering whether someone could give me some clarifications about xCode. I was reading a book on iOS and I was following it's instructions.
It was saying to create a header and an implementation file with the name test.h and test.m respectively. The test class will have UIViewController as superclass. This is all very fine...
Then, from the instructions, it says to drag out a View Controller from the object library onto the storyboard. Then, the book says:
"Now that the view controllers is in place, it’s time to set it up with the correct controller class. Select the view controller and bring up the Identity Inspector. In the Custom Class section of the inspector, change the class to test, and press Return to set it."
My question is: Is it really important to change the class of the view controller to test? Why can't I let the class remain as UIViewController? If I let the class remain as UIViewController, will the outlets and actions created on the view controller in the storyboard not be able to 'communicate' between the View Controller in the storyboard and the test.h and test.m files?
Thanks for reading
Kindest Regards
Yes, it is imperative that you set the class. Fortunately Xcode will not allow you to add outlets in the storyboard if the class set does not define them. If you don't set the correct class then the wrong class will be instantiated at runtime and your custom code will not run.
Keep in mind that the storyboard contains an archive of your design which can be unpacked and used at runtime. It doesn't work automatically and it needs to be configured properly. If, for example, you were to add outlets and actions pointing to an instance of UIViewController instead of test (whose name should start with a capital letter) then you would get an exception at runtime when the archive is unpacked and it is found that the outlets can't be connected, because UIViewController doesn't define them.
YES, it is mandatory. In addition to other answers posted here, I would like to tell you to think over this thing:
Suppose you have more than one Class & ViewController in your demo
project, how do you expect XCode to assign proper Classes to specific
ViewControllers?

"Launch screens may not set custom class names"

I'm trying to set the initial view controller to a custom class. In previous versions this worked but for some reason I cannot do it now.
I have a UIViewController class (IntroVC). In the storyboard I created a new View Controller object and set it's class (Identity Inspector -> Custom Class -> Class) to IntroVC. IntroVC is a .swift file with functions viewDidLoad() and didReceiveMemoryWarning() of class IntroVC: UIViewController.
Here are screenshots of XCode
Error
IntroVC
Storyboard
Anyone know how to solve this? What's up with this version of XCode?
I made a really simple mistake.
This error occurred when a custom class was set in LaunchScreen.storyboard. I should have set my custom IntroVC class in Main.storyboard.
Setting the initial VC class in LaunchScreen.storyboard to UIViewController and the initial VC class in Main.storyboard to IntroVC fixed the problem.
XCode 7.0.1 is fine. The mistake is my own.
Go through your View Controllers in Main.storyboard and make sure you don't have one that is both set to a custom class:
and has "Is Initial View Controller" checked:
You can only do one or the other. Somehow I had "Is Initial View Controller" still checked by mistake, and it took me a while to hunt that down!
Check if you're changing the "LaunchScreen.xib" file view class in the identity inspector. It should be a standard UIView, maybe you set it to a view controller class by accident.
This occurs due to if you are set the class name for the LaunchScreen.Storyboard file in the Identity Inspector. Just remove the class name and it will work fine.

How to add custom data source class using storyboard

I can't find the way to add my custom data source class of UICollectionView in the storyboard. The data source class has an interface like this:
#interface CalendarDataSource : NSObject<UICollectionViewDataSource>
I try to find the calendar data source in the scene sidebar but I can't. So I can't seem to link the class to my UICollectionView. Is there something I should do but I didn't?
If you want to reproduce the similar problem, just create a new project in XCode5, set up a UICollectionViewController, and create a new class just like above.
I'm currently rewriting the project described in http://www.objc.io/issue-3/ The Github repo is https://github.com/objcio/issue-3-collection-view-layouts This project managed to do this, however. My code is almost the same to the project but can't run because viewcontroller.collectionView.dataSource is uninitialized.
Doing the initialisation programmatically is another issue, but please tell me in the comment because all I got from the internet is setting dataSource to self. But setting it to self doesn't require introducing a new retained data source object, which I got stuck on.
Go to the Interface Builder.
Right-click on your Collection View in the storyboard, delete dataSource outlet (if any).
Type "Object" in the search text field of the Objects Library and drag an 'Object' to your view controller containing UICollectionView (i.e. do the same as you add any view or view controller to storyboard scene, with the exception you add not a view or view controller but an abstract object).
In the left-side 'Scenes' panel of your storyboard, highlight just added Object; in right-side panel go to the 'Identity Inspector' and type CalendarDataSource instead of pre-defined NSObject. In left side panel ('Scenes'), 'Object' will be renamed to 'Calendar Data Source' automatically.
In the left-side 'Scenes' panel of your storyboard, control-drag from your UICollectionView to the 'Calendar Data Source'; in pop-up appeared, select dataSource outlet.
You've done!

Xcode 5 does not recognize custom UIViewController subclass in storyboard

I have a storyboard app in Xcode 5 with many custom view controllers and segues and everything works well, except in one case. In this case, I have a "View Controller Scene" where I am trying to use a custom UIViewController subclass. But even though I specify the subclass, the entry in the sidebar is still called "View Controller Scene" and the View Controller entry for that scene is shown as just the generic "View Controller" (where in every other case, the scene label is changes to reflect the subclass, as is the View Controller entry).
So, Xcode does not appear to believe that I have specified a custom class for the View Controller for this scene. If it were only interface builder that was confused, that would be fine, but when I run the code, when I prepareForSegue: for the appropriate segue, the destinationViewController is a UIViewController, while I need it to be the custom subclass.
I know that my custom class must be a subclass of UIViewController, and it is (although several steps removed -- that is, it is a subclass of a subclass of a subclass of UIViewController).
The problem is not the Xcode 5 bug of not recognizing custom classes (the class name does show up in autocomplete for the Custom Class field) and Xcode has been restarted many times since this custom class was created.
So, what am I missing? What could cause Xcode 5 not to recognize a custom class for a UIViewController?
Happens all the time, easiest way to solve it: quit Xcode and run it again. The view controller should now be visible.
Its a thing that just happens sometimes, I usually ignore it, copy the name in and hit enter, but if its bothering you, you can try to clean and build your project, should start showing up then clean: cmd + shift + k build: cmd + b
good luck!

Resources