TTTableViewController help using two datasources

17 views
Skip to first unread message

david parcerisa

unread,
Feb 24, 2011, 11:20:39 AM2/24/11
to Three20
Hello, I need help with that.. I'm very new, so maybe I'm loosign
something really basic.

I have a TTTableViewController with a datasource and a simple query, I
would like to on a press of a button exchange this query and refresh
TTTableViewController contents.. this is possible? how you will do it?

thank you.

ambert ho

unread,
Feb 24, 2011, 2:36:55 PM2/24/11
to thr...@googlegroups.com, david parcerisa
I'm not sure what you mean by "on a press of a button exchange this query and refresh" - do you mean something like:
  1. The table view initially displays cached contents from the last time the app was open
  2. Pressing the button makes a network request that retrieves updated content from the server
  3. 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:
  1. My TTModel is backed by local storage (say sqlite, containing the cached contents) which is loaded into the in-memory objects at app startup
  2. Those objects are of course then loaded into the TTDatasource, which generates the table view items and subsequently table view cells
  3. 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)
  4. when the request returns, I modify the local storage with the new information and post an NSNotification (or you can implement a delegate)
  5. 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.



--
You received this message because you are subscribed to the Google
Groups "Three20" group.
To post to this group, send email to thr...@googlegroups.com
To unsubscribe from this group, send email to
three20+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/three20?hl=en

To learn more about Three20, check out
http://Three20.info/

daffy

unread,
Feb 24, 2011, 4:11:50 PM2/24/11
to Three20
In the button's selector funtion,try changing the values for
datasource according to your new query and calling [self.tableView
reloadData];
If that doesn't work, I've other way to do it too, but think this
would work for you fine.

David Parcerisa

unread,
Feb 24, 2011, 4:52:53 PM2/24/11
to thr...@googlegroups.com
yes thank you this is what i've done.

Reply all
Reply to author
Forward
0 new messages