views:

261

answers:

1

I am setting up routing to a TTTableViewController as follows:

[map from:@"myurl://filter/(initWithName:)" 
      toViewController:[FilterViewController class]];

and then, in another view controller I set up a mutable dictionary to pass through as my query:

// Set up dictionary and populate a field
NSMutableDictionary *filterDictionary;
filterDictionary = [[NSMutableDictionary alloc] init];
[filterDictionary setObject:@"test entry" forKey:@"test key"];

// Attach a query to the URL and open it
TTURLAction *theAction = [[TTURLAction actionWithURLPath:@"myurl://filter/search"] 
          applyQuery:filterDictionary];
[[TTNavigator navigator] openURLAction:theAction];

Finally, in the filter view controller, I can correctly access the values:

in .h:

@property (nonatomic, retain) NSMutableDictionary *filterDictionary;

in .m:

- (id)initWithName:(NSString *)filterName query:(NSMutableDictionary *)filters {
 if (self = [self init]) {
  self.filterDictionary = filters;
  NSLog(@"Filter Dictionary assigned : %@", self.filterDictionary);
 }
 return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
 if (filterDictionary) 
        [filterDictionary setObject:textField.text forKey:@"searchAddress"];
 [textField resignFirstResponder];
 return YES;
}

The dictionary is correctly mutable and I can add values etc. without problem. However, when my filterViewController is dismissed, I assumed the changed dictionary would be reflected in the parent - it was passed by reference correctly.

Am I missing something? Is my dictionary in the filterVC actually a copy due to a base class of Three20 somewhere?

A: 

I'm running into a similar issue. I suspect we may need to pass in a delegate (via that query), along with your dictionary as a separate object. Then have the parent honor a protocol defined in this new VC, wherein you can now pass back that dictionary at the proper time.

TTNavigator also has viewControllerForURL:query: (among others) for obtaining a VC without opening it, but perhaps passing in the query and having the VC "do the right thing" is enough, plus I think - accent on think - the idea is to start using URL Actions and not just URLs (in the Three20 sense).

Joe D'Andrea