NSObjects to URLs with TTNavigator to ViewControllers

22 views
Skip to first unread message

loosy

unread,
Jan 27, 2011, 3:02:20 AM1/27/11
to Three20
hello,

I'm using TTNavigator to push TTTableViewController. I want to pass
the object to ViewController when it is pushed.

TTNavigator *navigator = [TTNavigator navigator];
navigator.window = window;

TTURLMap *map = navigator.URLMap;

[map from:[Character class] name:@"character" toURL:@"tt://
character/"]; //mapped the class
[map from:@"tt://characterList/(init)" toSharedViewController:
[CharacterListController class]]; //derived TTTableViewController
[map from:@"tt://character/(initWithCharacter:)"
toSharedViewController:[CharacterDetailController class]];


and My "CharacterListController" is implemented as follows:

@implementation CharacterListController

- (id)init {

if (self = [super init]) {

self.tableViewStyle = UITableViewStyleGrouped;
self.title = @"Characters";

TTListDataSource *dataSource = [[[TTListDataSource alloc]
init] autorelease];

NSMutableArray *characters = [[CharacterData
sharedCharacterData] characters]; // returns the initialized object
from the array
for(int i = 0; i < [characters count]; i++) {

Character *character = (Character *) [characters
objectAtIndex:i];


//NSLog(@"Character URL:%@",[character
URLValueWithName:@"character"]);
TTTableItem *tableItem = [TTTableSubtitleItem
itemWithText:character.name
subtitle:[NSString
stringWithFormat:@"Level %d %@", character.level,
character.rpgClassName]
URL:[character
URLValueWithName:@"character"]]; ///
object to pass


[dataSource.items addObject:tableItem];
}

self.dataSource = dataSource;

}
return self;

}

and when cell is tapped I'm pushing "CharacterDetailController" and
want to call its method "-(id)initWithCharacter:(Character *)"

@implementation CharacterDetailController

- (id)intWithCharacter:(Character *)character
{
if (self = [super init]) {
NSLog(@"character:%@",[character description]);
}
}

But when I run the application it crashes when
"CharacterListController" is pushed while its data source is
initialized at:

''
TTTableItem *tableItem = [TTTableSubtitleItem
itemWithText:character.name
subtitle:[NSString
stringWithFormat:@"Level %d %@", character.level,
character.rpgClassName]
URL:[character
URLValueWithName:@"character"]]; /// here the application
crashes

"
here is the stack trace of the crashing reason:

Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '+[NSInvocation
invocationWithMethodSignature:]: method signature argument cannot be
nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x01044be9
__exceptionPreprocess + 185
1 libobjc.A.dylib 0x011995c2
objc_exception_throw + 47
2 CoreFoundation 0x00fb4b09 +[NSInvocation
invocationWithMethodSignature:] + 553
3 MyTest 0x0000a765 -[TTURLSelector
perform:returnType:] + 232
4 MyTest 0x0000ac98 -[TTURLWildcard
convertPropertyOfObject:] + 105
5 MyTest 0x00006f72 -
[TTURLGeneratorPattern generateURLFromObject:] + 379
6 MyTest 0x00006939 -[TTURLMap
URLForObject:withName:] + 212
7 MyTest 0x000757e9 -
[NSObject(TTCategory) URLValueWithName:] + 102
8 MyTest 0x000ac27b -
[CharacterListController init] + 352
9 MyTest 0x00009593 -
[TTURLNavigatorPattern createObjectFromURL:query:] + 261
10 MyTest 0x00006312 -[TTURLMap
objectForURL:query:pattern:] + 241
11 MyTest 0x0000cca5 -[TTBaseNavigator
viewControllerForURL:query:pattern:] + 640
12 MyTest 0x0000c223 -[TTBaseNavigator
openURLAction:] + 843
13 MyTest 0x000ab80a -
[RPGCharsAppDelegate applicationDidFinishLaunching:] + 411
14 UIKit 0x0054e253 -[UIApplication



Any help will be appreciated. plz help me I'm stuck here for two days
and struggling to get things right way.

Sirius Dely

unread,
Apr 13, 2012, 4:37:32 AM4/13/12
to thr...@googlegroups.com
For someone who still stuck with this...

Should be something like this:

[map from:[Character class] name:@"character" toURL:@"tt://character/(one of you Character class' property name)"];
example
[map from:[Character class] name:@"character" toURL:@"tt://character/(firstName)"];

From documentation:

Parameter substitution

You may have noticed from the example above that mapping an object to a URL allows you to use properties from the NSObject to create the URL. Simply include the parameter name, surrounded by (parenthesis), andURLValueWithName will automatically substitute it. Any property of the NSObject can be used to generate the URL, allowing you to break the object down into a unique URL representation.

http://three20.info/article/2010-10-06-URL-Based-Navigation#urlmapping

Reply all
Reply to author
Forward
0 new messages