views:

58

answers:

3

So, I've been making iOS apps since the first iPod touch came out, but something has always flabbergasted me; why is the list of new Cocoa Touch classes restricted to subclasses of NSObject, UIView, and UITableView? I routinely make subclasses of UIImageView and UIViewController.

Am I "Doing It Wrong™?" Have I totally misunderstood MVC to the point where I make Controller classes where I shouldn't? What is the philosophical reasoning for requiring classes to never descend from a basic controller class?

+1  A: 

What gives you the idea that you aren't supposed to subclass UIViewController? This is directly from the documentation for UIViewController:

In a typical iPhone application, there is usually at least one custom subclass of UIViewController and more often there are several.

The C of MVC is supposed to be the least re-usable part it's whole job is to mediate between M & V. If you find something that is in the C section of your code that you have to copy and paste into several subclasses of a given object or into several projects that code should be moved elsewhere.

If you are just basing this off the fact that there is not a nice popup menu item that says UIViewController, don't worry about it Apple has just not bothered to write a template file for that class yet.

theMikeSwan
A: 

Like @theMikeSwan says, there simply aren't GUI templates for this when you create a new class in Xcode GUI. But you can always create a new subclass whose parent is initially NSObject. After that, you just go to your code and change the parent class to whatever you like.

So... no, you are not doing it wrong in the sense that you rightly understand that often you want to subclass UIViewController; but yes, you are doing it wrong since you assume you shouldn't do this only because Xcode GUI does not support it :)

Jaanus
Thanks for the answer. I just wish there was a free form text field to define whatever descendent I want. The lack of that field makes me feel like I should only be descending from certain classes. :)
Khakionion
+1  A: 

Uhm... maybe it's just me, but I see a UIViewController subclass template when I choose new File.

UIViewController template

Ashley Clark