Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about delegating from ComponentController to ViewController #96

Closed
cfcommando opened this issue Apr 10, 2015 · 2 comments
Closed

Comments

@cfcommando
Copy link

Would it be kosher to include a weak reference to a delegate (i.e. a ViewController) in the context so that the component can set its controller's delegate?

Is that a valid pattern (I suspect possibly not)? Are there better ways to route events?

Specifically, I want to implement the tap on a couple of buttons in a component to present view controllers from the current one, and was wondering what strategies are preferred to connect component actions back to their owning view controllers.

@adamjernst
Copy link
Contributor

Would it be kosher to include a weak reference to a delegate (i.e. a ViewController) in the context so that the component can set its controller's delegate?

Yes (although I'd prefer having the controller read the component's weak reference and set it on itself, rather than having the component do it).

Are there better ways to route events?

The way we do it at Facebook: we pass down a "navigator" object as part of the context. A simplified version:

@protocol Navigator
- (void)pushViewController:(UIViewController *)vc animated:(BOOL)animated;
@end

Behind the scenes, the actual implementation holds a weak reference to the parent view controller. On demand it looks up the view controller's navigation controller and pushes a view controller, etc.

We find this hides the actual view controller away from the components, making them more reusable.

@cfcommando
Copy link
Author

Very enlightening. I had assumed until now that the context was intended mainly as a conduit for data rather than connecting events.

Thanks for the clarity!

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

No branches or pull requests

2 participants