Im starting iPhone developpement on Xcode and I don’t get what the difference between a View and a View Controller is or between a Table View and a Table View Controller. Does anyone have a simple explanation?
Im starting iPhone developpement on Xcode and I don’t get what the difference between
Share
Lets get to the
UIViewand theUIViewControllerclass firstUIViewControlleris a Cocoa Touch class built for the purpose of managing UIViews. It expects to have a view hierarchy, but you don’t “automatically” get a view (this is slightly inaccurate; see edit below). Usually you will obtain views by callinginitWithNibNameon your view controller.There is some built-in magic in Interface Builder which knows that if File’s Owner is a
UIViewController(or subclass), there is a property called view. That’s about it.Once you have linked a view controller and a view, the view controller does a fair amount of work for you: it registers as a responder for view touch events, registers for device rotation notifications (and handles them automatically, if you wish), helps you take care of some of the details of animation, and handles low-memory conditions semi-automatically.
If you don’t call
initWithNibNameor set the view property manually, the view property getter will invoke loadView if view is nil. The default implementation of loadView will see if you’ve set nibBundle and nibName and attempt to load the view from there (which is why you don’t have to call initWithNibName, most of the time), but if those properties aren’t set, it will instantiate a UIView object with default values. So technically, yes, it does automatically come with its ownUIView, but most of the time that’s of little value.Now coming to the TableView and the UITableViewController class
A
TableViewControlleris aViewControllerwith a TableView built in. This will have the delegate methods needed already declared and setup. This VC is already a TableView delegate and datasource. It cannot be resized. Upside is ease of use, downside is very limited flexibility.A
TableViewis just that a TableView (subclass ofUIView). It can be added to a ViewController and resized, used alongside another view based object, etc. The upside is the flexibility, the downside is that you have to setup the delegate and datasource methods yourself (in my opinion, well worth the time to get the flexibility).One other note is that when using the new Static TableView cells (part of iOS5), you have to use a TableViewController.
Also please check the following links for a detailed explanation of the methods.
view and viewcontroller
What are controller classes?
What is the difference between UIView and UIViewController?
What's the difference between the RootViewController, AppDelegate and the View Controller classes that I may create?