Skip to content

Conversation

@abiaad
Copy link

@abiaad abiaad commented Nov 25, 2012

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];
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the method signature to (and change query):

- (void)navigateTo:(NSString*)route navigationController:(UINavigationController*)navController parameters:(NSDictionary*)parameters;

@aaronbrethorst
Copy link
Owner

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.

@abiaad
Copy link
Author

abiaad commented Nov 25, 2012

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 ?

@aaronbrethorst
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants