views:

693

answers:

1

I've got a button that toggles setEditing on a TTTableView. Previously I'd been using a "regular" UITableView and the following method to actually delete the data, but I don't see anything similar in the Three20 classes and using my method doesn't get called when the delete button is pressed on a row.

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //do work}

I must be missing something but I can't figure out where. It seems like setEditing in TTTableViewController isn't connected up to anything. There's a didDeleteObject method but I've no idea whether that's supposed to be a replacement for the above method or not. Any input would be greatly appreciated.

+2  A: 

Your experience with TTTableViewController is also going to be a little different than you might expect because it does not inherit from UITableViewController. Unlike most iPhone tutorials that have the table's view controller also implement the UITableViewDelegate and UITableViewDataSource protocols, Three20 implements them through separate classes: you are expected to set the controller's dataSource property with a model instance, and the controller creates its own delegate (in the createDelegate method, which you can override).

The method you want to implement, tableView:commitEditingStyle:forRowAtIndexPath:, is part of the UITableViewDataSource protocol, so you're going to need to implement that on your model class, and not on the controller itself.

The TTTableViewController does not directly do anything with setEditing:animated:, and just inherits the base implementation from UIViewController.

The model:didDeleteObject: method that you see is inherited from TTModelViewController as an implementation of the TTModelDelegate protocol. It's there so that changes to the underlying data model can notify the view layer of changes. For instance, if your application is downloading data from the web, rows may appear and disappear all the time, independent of what's going on with the user interface. If you're trying to drive edits through the UI, you shouldn't need to mess with that.

Sixten Otto
This is a great summary of how Three20's TTModelViewController was used to reorganize the controllers. Like you said, it's important to be careful to discriminate the TTModelDelegate methods from the UITableViewDataSource ones.If this answer isn't accepted, I might write some sample code in a new answer on this.
Justin Searls