Very nice! Thanks for this. This and the Hello World you did are really helping me get this down.
I have a question regarding code consistency and conventions. I am new to objective-C but most code I see has method names that start with lower case, and are camelCased with no underscores. In your tutorials I have seen camelcased methods, camel cased that start with a capital letter, and lowercase underscored method names. Are there common conventions for that or is it just your preference? I realize the compiler doesn't care, but most languages have a "Best Practice" around these matters.
Also, I managed to get the delete button to actually work. It took some digging thorugh the docs to figure out how what methods get called when a cell is confirmed to be deleted, but the method you mention at the end is only half the story. You need the delegate method:
Code:
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Which gets called on the master view when the delete button is hit. I added a 3 line method to MasterView and it deletes items like a charm!
Code:
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[appController.masterList removeObjectAtIndex:[indexPath indexAtPosition:1]];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
[self buttonPushed];
}
The first line of the method removes the item from the array that feeds the table. So you update your data source BEFORE you update your view. The NSIndexPath class can keep track of your position in nested table views and table view sections. [indexPath indexAtPosition:1] returns the index, as an int, of the table cell that had its delete button tapped.
The next line updates the table view. It expects an array of NSIndexPath objects, but we only have 1, so we make a little array of NSIndexPath objects right inline. This removes the table row from the view, and animates it all pretty.
The last line resets our button. After each deletion the table view automatically exits edit mode. So without this last line, you would still have a blue "Done" button. So after the deletion, you have to simulate hitting the "Done" button by calling the method that handles tapping that button.
Just figured some people might like to know how to tackle that piece of it, before the next video.
Keep it up, man. you rock.