Graphics Programs Reference
In-Depth Information
// Insert this new row into the table.
[[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:ip]
withRowAnimation:UITableViewRowAnimationTop];
}
Build and run the application. Tap the New button and watch the new row slide into the
bottom position of the table. Remember that the role of a view object is to communicate
model objects to the user; updating views without updating the model objects isn't very
useful.
Also, notice that you are sending the message tableView to the ItemsViewCon-
troller to get at the table view. This method is inherited from UITableViewCon-
troller , and it returns the controller's table view. While you can send the message
view to an instance of UITableViewController and get a pointer to the same ob-
ject, using tableView tells the compiler that the object returned will be an instance of
class UITableView . Thus, sending a message that is specific to UITableView , like
insertRowsAtIndexPaths:withRowAnimation: , won't generate a warning.
Now that you have the ability to add rows and items, remove the code in the init meth-
od in ItemsViewController.m that puts 5 random items into the store.
- (id)init
{
// Call the superclass's designated initializer
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
for (int i = 0; i < 5; i++) {
[[BNRItemStore sharedStore] createItem];
}
}
return self;
}
Build and run the application. There won't be any rows when you first fire up the applica-
tion, but you can add some by tapping the New button.
 
Search WWH ::




Custom Search