I'm not sure what you mean by "on a press of a button exchange this query and refresh" - do you mean something like:
- The table view initially displays cached contents from the last time the app was open
- Pressing the button makes a network request that retrieves updated content from the server
- On receiving the server response, the table view refreshes and displays the updated content
I'm not sure what the authors of Three20 have in mind for this scenario and there are multiple ways to do this, but here's what I do:
- My TTModel is backed by local storage (say sqlite, containing the cached contents) which is loaded into the in-memory objects at app startup
- Those objects are of course then loaded into the TTDatasource, which generates the table view items and subsequently table view cells
- I have a network request that I kick off in the background when the app loads, to get the query (in your case you can just link it to the button you talked about)
- when the request returns, I modify the local storage with the new information and post an NSNotification (or you can implement a delegate)
- In my controller, I have a listener for that NSNotification, at which point I call [self invalidateModel]***, which reloads the datasource and hence reloads the model, which picks up the new contents I just stuffed in. -TTTableViewController#invalidateModel also reloads the tableView, and so I am now displaying the updated content. Good to go!
Let me know what's confusing, I know Three20 can be quite just that. I'll tell you that one of the most confusing parts of the three20 MVC model coming from regular iOS dev is the fact that:
- in regular iOS dev, your UITableViewController is often also <UITableViewDataSource> in addition to UITableViewDelegate
- in three20, this responsibility is split up into two entities: TTTableViewController is responsible for the tableView, while TTDatasource implements the <UITableViewDataSource> protocol
Ambert
*** You can browse through the Three20/src/three20UI xcode project to see what invalidateModel does, but it basically will destroy the model, called [self createModel], and reload the tableview. So to make this work you have to implement -(void) creatModel. You can look through the example three20 projects for an example of this.