I am just curious. In IB, we can put a tableviewcontroller. However, as far as I know, we always subclass that tableview controller right? That way we can implement delegate, etc.
However, it seems that for some “default” behavior, IPhone intended tableviewcontroller to be used as is. Otherwise, why would IB let us put tableViewController like that?
Are there any sample code where people use tableViewController without subclassing?
Where does they implement things like what cells to draw, etc. then?
I guess the right answer of the question is that it’s simply ridiculous to use a UITableViewController without sub classing. No body is doing it. Please correct me if I am wrong. I am just curious.
Whether you use a subclass of
UITableViewControllerorUIViewControlleryou need to set the data your table is going to display, otherwise, what’s the point of a blank table? To achieve that you have to subclass and implement some methods. It’s also a good idea to keep the delegate and the datasource in the same controller, unless the complexity really asks for different classes.That being said, I always create my own table controllers as a subclass of
UIViewControllerand implement the table controllers methods myself, because it gives you more flexibility. Matt Gallagher has several posts on how and why. See UITableView construction, drawing and management (revisited).If you want to give it a try, create a subclass of
UIViewControllerwith a XIB and add the following sample code:Then add a
UITableViewobject to the XIB, link thetableViewof the controller to theUITableViewobject, and link the delegate and datasource of theUITableViewto the controller.