What is message sequence in building the table?


#1

In this chapter we add rows one at a time with the addNewItem: method. In it we create a new item in the shared store, get its index (it will be the last item in the array), create an index path for it and send the message insertRowsAtIndexPaths:withRowAnimation: to place the item in the table view. Makes sense. In Chapter 9,we add 5 items to the shared store in the init method. We do not send the message insertRowsAtIndexPaths:withRowAnimation: (???). In both cases (Chapter 9 and 10) we have implemented the two required methods in the UITableViewDataSource protocol, tableView:cellForRowAtIndexPath: and tableView:numberOfRowsInSection:. Now, for the questions.

  1. For each case (chapter) how is the table built? What is the sequence of messages used to build the table view?
  2. The Apple Documentation says in the Table View Programming Guide for iOS under “Inserting and Deleting Rows and Sections” that the table view’s data source must implement tableView:commitEditingStyle:forRowAtIndexPath: if it wants to insert or delete a row. It must also send the message insertRowsAtIndexPaths:withRowAnimation: to the table view to direct it to adjust its presentation. We do neither in Chapter 9. How then, are rows added to the table?

#2

For those of you curious, the table view is “built” in the sequence that starts with sending the message makeKeyAndVisible to self.window in application:didFinishLaunchingWithOptions: ([self.window makeKeyAndVisible]). Remember the two required methods from the UITableViewDataSource protocol, tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath:? Somewhere in makeKeyAndVisible or in messages it sends, tableView:numberOfRowsInSection: is sent followed by tableView:cellForRowAtIndexPath:. That’s why the table view’s data source is required to implement them … they will be called.