I made a XIB that only consisted of a UITableView in IB. It was brought to my attention that it is possible to subclass UITableViewController and do away with the xib entirely.
My question is, how do you do this?
So far the only thing I have changed is my .h to be…
@interface MyView : UITableViewController
and removed my XIB. Obviously I get an error that states
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with <path>
name 'MyView''
so my question is, what else is left in order to accomplish this subclassing correctly?
There are two ways to set up your view controller in iOS.
-initWithNibName:bundle:, passing the name of your .xib file as the first argument, and (unless you’re doing some advanced stuff)nilas the second argument . The OS will look for your .xib file and unserialize it into a bunch of objects and attach them to your view controller. Then the OS calls your view controller subclass’s-viewDidLoad:method, where you finish setting things up.-init, or for a table view controller,initWithStyle:. The OS then calls your subclass’s-loadViewmethod, where you manually instantiate your view hierarchy.It sounds like you just need to instantiate it with
-initWithStyle:instead of-initWithNibName:bundle:.