Xcode 5 does not recognize custom UIViewController subclass in storyboard - ios

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!

Related

How UIViewController interact with Storyboard under the hood

I'm new to iOS development and this could be a stupid question for some experienced guys...
When I create a new iOS project in Xcode, I get a ViewController class and a storyboard which sets its Custom Class to this ViewController. It looks like there is a "Storyboard" class holding an instance of ViewController, however, I cannot find where this "Storyboard" class is defined.
Even though I know how to create multiple subclasses of UIViewController to handle different views interaction following some tutorials, I still find it uncomfortable to associate these subclasses to the storyboard by selecting them in the storyboard panel. I would rather see something like a "Storyboard" class holding an array of UIViewController.
So my question is, how these UIViewController interact with the Storyboard under the hood?
Thanks
Roughly, it happens as follows:
App launches.
App loads storryboard.
Depending on app's navigation structure, app instantiates each view controller inside the storyboard as needed.
The storyboard contains detailed information on:
Which custom subclass of UIViewController, UINavigtionController, etc. to use for instantiating each view controller in the storyboard.
How to map (connect) each if its view controllers' subviews to the corresponding custom classes' outlets and actions.
But seriously, read Apple's docs. It's all there.
UIViewController has a property named storyboard which refers to the storyboard file associated with the viewcontroller subclass.
Also the view controller code are interecting with the storyboard with connections symboled with #IBOutlet and #IBAction.

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?

Storyboard gets rid of `customModuleProvider="target"` on XML and stops finding class

I am trying to debug a problem that is happening on my Xcode install that makes my Main Storyboard not find my custom classes. Steps to reproduce:
Create a single view application
Run the app without any modifications, ensuring everything still works as supposed
Go to the main storyboard, click the yellow icon for the view controller, then focus the custom class input where ViewController is already filled. Hit enter.
When I do this, Xcode removes an attribute customModuleProvider="target" from the viewController node in my Storyboard, which causes the app to not find the custom class ViewController anymore.
How can I fix the project, allowing the Storyboard my classes again?

UIWebView IBOutlet Connection issue

So I'm going to try to explain my issue as best I can.
I have 2 View Controllers on a Storyboard. One is the "main" VC and the second is a "EULA" VC.
The main view controller has a UIWebView which loads the primary UI and works fine. This controller uses code to perform a Modal segue to the EULA VC which is created in the interface builder. This also works fine.
Now here lies my problem. The EULA view controller also has a UIWebView on it but I can't seem to connect this view controller to any connection by means of CTRL + drag. The "main" UIWebView is connected to ViewController.h
This is how I create my connection with CTRL + drag:
My question is why am I able to connect the first UIWebView on the Main view controller but not the other UIWebView on the EULA view controller? What am I missing?
Have you set up the EULAViewController.h as the custom class for the ViewController in Interface builder? Select the UIViewContoller in Interface Builder and in the third tab make sure the class is correct. Here is a screenshot explaining what I am saying:
Also make sure you have selected the correct file in the right pane, both red boxes should show the name of your custom UIViewController subclass:
I am think this is a bug in XCode or what. But this is very rare issue. I also got this issue sometime. So posting a solution which can make you little nervous to implement. But it works for me sometimes. You can try it . -
Just create a new UIViewController subclass in your project and name it something slightly different than the first. Then, copy/paste all code from old non-working UIViewController into the new UIViewController subclass (.h and .m) and change all relevant symbols according to the new UIViewController subclass name. After doing this I found everything worked as normal in terms of trying to control-drag wiring the buttons.
Happy coding. :)
Recreating the class files, renaming the view to something else then back to EULAViewController AND following these steps I was able to fix the issue.
Close the project you are working on with.
Delete the【DerivedData】folder of you project. (This folder may
inside your project's folder, or inside
~/Library/Developer/XCode/DerivedData/(your project)/ ) or somewhere
else that were setup by you.
restart you project.

Refactoring a UITableViewController subclass to a UIViewController subclass

In my app, I wanted to show a table in the "full screen," so I created a subclass of UITableViewController. When I want to show the table, I just instantiate it and use pushViewController:animated:. Now I've decided that I actually want to show it as a modal, so I want to give it a navigation bar with a "Done" button. I believe this means that I now need to make this a UIViewController subclass instead of a UITableViewController subclass, since it will now be more than just a table. I'm not really sure if this is something that can be done, though; I've created an xib, but Xcode doesn't seem to want to let me use that xib to create IBOutlets in the .h file, so I don't think the two are "connected."
I ran into this problem once before and worked around it by just creating a new UIViewController subclass and xib and just copy-and-pasting all the stuff I needed from the UITableViewController subclass's files into the new subclass's files. I knew then as I know now that that was a hacky and unpleasant solution, though. Does anyone know how something like this can be done properly?
Also, to avoid this problem in the future, should I just never make top-level views like this in the future and just make sure everything I use pushViewController:animated: or presentModalViewController:animated: with is a UIViewController subclass? Or is it safe to do what I've been doing?
Several things you mention in your question indicate some misunderstandings. First, if you're pushing you table view controller, then it has to be embedded in a navigation controller, and thus will have a navigation bar -- you can add a done button to this bar, if that's all you're trying to change. No need to refactor your code.
If you want to use a UIViewController instead of a table view controller, you should be able to hook up your nib. Did you change the class of the files owner in the nib to your UIViewController class? After you do that, you should be able to hook up the outlets.
There's nothing "hacky" about copying and pasting code from a table view controller into a view controller. I do this all the time, rather than writing out all those files.
I'm not sure what you're asking in the last question. How you get your table view on the screen (pushing or presenting) has nothing to do with whether what you're showing is a table view controller or a view controller. You should use the one that best fits your needs.

Resources