Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between UIViewController and ViewController?

Tags:

objective-c

I just noticed after adding a new ViewController that it isn't a UIViewController like the one created by Xcode. I didn't find an answer on google so I hope one of you could explain the difference between these two to me.

Edit

To clarify my question:

This is the declaration of my UIViewController:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

And this is the declaration of my ViewController:

 #import "ViewController.h"

@interface GameViewController : ViewController

What is the difference between these two ViewControllers?

like image 236
Dalibor Avatar asked Feb 08 '23 11:02

Dalibor


1 Answers

What is the difference between these two ViewControllers?

Not a great deal, but it depends on the functionality defined in ViewController. It's fairly common to create a base class that contains common functionality you want in all derived classes, and view controller classes are no exception here.

However if ViewController contains no real functionality, then you can simply remove it and derive GameViewController directly from UIViewController:

#import <UIKit/UIKit.h>

@interface GameViewController : UIViewController

I would be very surprised if Xcode generated both ViewController and GameViewController in one operation, as you imply in your question, however. If it did, then that's new to me and I cannot see why it did it.

like image 190
trojanfoe Avatar answered Feb 26 '23 11:02

trojanfoe