ABRouter icon indicating copy to clipboard operation
ABRouter copied to clipboard

Add query system to transmit objects

Open abiaad opened this issue 12 years ago • 3 comments

I've changed main structure by creating a custom UIViewController : ABViewController. All controllers have to inherit from this new class. Then you have to fill an NSDictionary of your object you want to transmit and set it to query variable of your class (done automatically with you navigation method call).

Hope you'll enjoy it :)

- (IBAction)viewObject:(id)sender
{
    NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate date],@"date",nil];
    [[ABRouter sharedRouter] navigateTo:@"/object" withNavigationController:self.navigationController andQuery:query];
}

abiaad avatar Nov 25 '12 19:11 abiaad

I like where you're going with this, but I'm not a fan of requiring users to change their entire view controller hierarchy. I'd much prefer to give users the option of using a params object (as you're doing here), but make it optional instead. What I'd imagine this could look like is that the Routable protocol has a new optional property on it: @property(copy) NSDictionary* parameters that is detected in the routing methods. i.e.:

- (void)modallyPresent:(NSString*)route from:(ABViewController*)viewController parameters:(NSDictionary*)parameters
{
  UIViewController<Routable> * pushMe = [self match:route];
    pushMe.apiPath = route;
  if ([pushMe respondsToSelector:@selector(setParameters:)])
  {
    [pushMe performSelector:@selector(setParameters:) withObject:parameters];
  }
  UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:pushMe] autorelease];
  [viewController presentModalViewController:nav animated:YES];
}

I think it's great to offer a stub implementation of the Routable protocol in a new view controller. It just shouldn't be mandatory.

aaronbrethorst avatar Nov 25 '12 19:11 aaronbrethorst

I see what you mean and you're right but I don't like the idea of declare all the time the apiPath variable. If there is another way to avoid ABViewController inheritance and apiPath declaration in all controllers it would be great, don't you think ?

abiaad avatar Nov 25 '12 20:11 abiaad

That would be ideal. However, I don't think it's possible. In terms of gaining the greatest benefit with the least pain, I think that the apiPath declaration is the best option. I'd be open to alternatives, though.

aaronbrethorst avatar Nov 25 '12 20:11 aaronbrethorst