Passing objects as parameters in URL Navigation

71 views
Skip to first unread message

CVertex

unread,
Jul 16, 2009, 12:37:39 PM7/16/09
to Three20
Hi,

Excellent library, very well desigend. There are so many cool controls
to play with.


I have an issue where my data source API doesn't allow for getting a
single item. E.g. /api/story/detail/24 doesn't exist and all the
information comes through the search API /api/story/search?query=blah

This means when I have all the information for any particular item I
need when I'm constructing my search results table as well as details
results.

My question is how can I pass a deserialized object across to another
page using the navigation classes?

for (Story* s in result.items) {
TTTableItem* item = [TTTableTextItem itemWithText:[s title]
URL:@"tt://story/hello"]; // how could I construct this API?

[_items addObject:item];
}

I can think of a few options, but I would like to know what others
think is the best approach. Im very new to iphone dev.

1. Have a LRU Subsystem that keeps a list of all deserialized Stories
fetched during search. Make the subsystem a singleton and use it
statically in the details view.
2. Somehow pass an an NSObject over the navigation system
3. Serialize the Story object into a URL friendly string and use the
URL.
4. Something else I haven't thought of

Thanks,
CV

Thanks again for a rad library.



Joe Hewitt

unread,
Jul 16, 2009, 3:32:16 PM7/16/09
to Three20
You can pass a live object using the query dictionary in
openURL:query: You can then receive the query dictionary by adding
query:(NSDictionary*)query to the selector that your URL is mapped to.

I have it on my todo list to allow TTTableItem to have an "id object"
property, which would automatically be sent in the query dictionary as
described above.

- Joe

CVertex

unread,
Jul 16, 2009, 10:49:20 PM7/16/09
to Three20
Thanks Joe!

You possibly need to store an id object and NSString* key for the
query dictionary.

-CV

Elliot Bowes

unread,
Jul 28, 2009, 12:40:32 PM7/28/09
to Three20
Hi

Is there an easy way to accomplish the case where a controller *only*
wants to receive the query dictionary (which will contain a live
object).

For instance:

I'm in the same situation as CVertex, in that I cannot retrieve the
data for an item by an ID number. Thus I wish to map "myapp://
itemDetails" (with no extra parameters etc.) to something like
[[MyDetailsController alloc] initWithQuery:(NSDictionary*)query].

Perhaps I'm missing something when tracing through the source code for
TTURLMap/TTURLPattern and the TTNavigatorDemo examples, and there
already is a way to do this. If so, it'd be nice if an example could
be added to TTNavigatorDemo. Otherwise, may I request this as a
feature.

In the meantime, is there a relatively simple workaround? I'd rather
not have to handle anything in the app delegate (as in the "tt://order/
confirm" example), as this is a component in a library used across
multiple apps.

Thanks in advance,

Elliot

Edward Benson

unread,
Aug 5, 2009, 1:07:00 PM8/5/09
to Three20
Elliot --

Did you ever figure this out. I am having the same problem as well: I
*only* want to send the query dictionary.

-Ted

klazuka

unread,
Aug 5, 2009, 1:20:21 PM8/5/09
to Three20
I was able to make it work In TTStyleBuilder by doing the following:

// AppDelegate URL registration:
[map from:@"tt://value/new?" toViewController:
[NewObjectPickerController class]];

// Initializer for my view controller (NewObjectPickerController):
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query
{
Class baseClass = [query objectForKey:@"baseClass"];
NewObjectPickerController *controller = [self
initWithBaseClass:baseClass];
controller.delegate = [query objectForKey:@"delegate"];
return controller;
}

// Client code to open the URL and pass it the data:
NSDictionary *query = [NSDictionary
dictionaryWithObjectsAndKeys:
myDelegate, @"delegate",
myClass, @"baseClass",
nil];
[[TTNavigator navigator] openURL:@"tt://value/new?" query:query
animated:YES];

-keith

Elliot Bowes

unread,
Aug 5, 2009, 2:48:01 PM8/5/09
to Three20
Cheers Keith

I'll give this a try tomorrow.

Elliot

Elliot Bowes

unread,
Aug 6, 2009, 10:05:50 AM8/6/09
to Three20
Hi

Gave it a try today. It works great thanks.

I dropped the ? from the URL when mapping it as it didn't seem to make
a difference whether it was there or not.

Also, for anyone wondering, query parameters appended to the URL (when
using openURL) get parsed and URL decoded into the query dictionary.

For example, a URL like "myapp://details?title=A%20Long%20Title" will
receive a query dictionary with the string "A Long Title" for the key
"title".

Regards,

Elliot

On Aug 5, 6:20 pm, klazuka <klaz...@gmail.com> wrote:

CVertex

unread,
Aug 30, 2009, 12:35:14 PM8/30/09
to Three20
Hi,

I solved this problem by adding
NSString* _queryKey;
NSObject* _queryObject;

@property (nonatomic,copy) NSString* queryKey;
@property (nonatomic,retain) NSObject* queryObject;

to TTTableLinkedItem and then added the following to
TTTableViewDelegate
if (item.queryKey && item.queryObject) {
NSMutableDictionary* q = [NSMutableDictionary
dictionaryWithObject:item.queryObject forKey:item.queryKey];
TTOpenURLWithQuery(item.URL,q);
} else {
TTOpenURL(item.URL);
}

I had originally tried URL encoding my queryObject onto the URL, but
that failed miserably as the object I was dealing with was a large
amount of XML. Even after encoding it didn't quite work.

The limitation of my work around is that you can't add multiple query
objects/keys for a tableitem.

Can anyone suggest a better implementation that allows me to pass many
objects along a TTTableLinkedItem?

Regards,
CV

Bill Dodd

unread,
Sep 9, 2009, 9:49:43 PM9/9/09
to Three20
Guys, just wanted to say thanks for this post. It was super-helpful
in my implementation of 320 for Columbia Southern University's
upcoming iPhone app when it came time for me to pass around categories
from the TTTableviewcontroller to my other view controllers..

You guys have done a great job through this group in providing
excellent tips.
Thanks again for the effort..


Best,
Bill

CVertex

unread,
Sep 10, 2009, 7:53:13 AM9/10/09
to Three20
Glad this was helpful.

I would still like to see this feature added to joehewitts trunk, or
someone to at least comment on my approach to the problem.

Joe has said before he'd like to implement this - I hope he can
provide some hints as to how it should look/work so maybe we can help
get it in the origin/master.

Regards,
CV
Reply all
Reply to author
Forward
0 new messages