I am trying to do something very basic. I want a tab bar application where some of the tabs contain table views. I am working with Interface Builder.
I can create a tab bar app starting from an empty app using code found in Beginning iPhone 6 Development. That’s easy. I create the app, create an empty nib, then drag a tab bar controller into the empty nib. Set up the hookups, the root controller, and load the nib from the App Delegate. Works fine. I can then create more nibs and assign each nib to each tab item. If I add a label to each nib, it’s fine.
I can create a table view app. Start with a view app, go to my main nib, drag in a table view, implement the methods inside the class, hook everything up, it’s fine.
But when I combine those two, it doesn’t work. Specifically, get the tab app working. From one of the views (separate nib), delete the label and add a table view instead.
I do all the same things as I do in the simple version. I cut and paste code. But when I run it, I get messages about invalid selector being sent (numberOfRowsInSection).
So… clearly I have to do it differently.
Comments?
You need to implement the tableview delegate methods. There are specific methods that drive the data and delegate of a tableview. Anytime the tableview loads your app will be looking for these methods. One of them being (numberOfRowsInSection). Make sure you have hooked up your delegate and datasource in IB (by right clicking the tableview and using the drag commands to select File’s Owner). Then you have to implement the appropriate methods to setup a tableview.
These methods can be found on the Apple Doc site for configuring a tableview linked below:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html