Closed oleksii-demedetskyi closed 11 years ago
You can reuse the same view model for multiple views in your hierarchy, if it makes sense to do so.
The view model hierarchy should reflect the abstract structure of the presented data, while the view layer may become more complex to actually support the desired presentation.
@jspahrsummers In case we want child view controllers to have their own view models, who is responsible for creating view model for child view controllers? Is it parent view controller, parent view model or child view controller?
@xNekOIx Generally, the parent view model would create the child view model. By doing it this way, you can observe the view model to know when to present the next VC. For example:
// In the parent view controller
RACSignal *childViewController = [RACObserve(self.viewModel, childViewModel)
map:^(ChildViewModel *viewModel) {
return [[ChildViewController alloc] initWithViewModel:viewModel];
}];
[self.navigationController rac_liftSelector:@selector(pushViewController:animated:) withSignals:childViewController, [RACSignal return:@YES]];
Hi. I have a question about using MVVM approach with container controllers. For example. We have container that show
ListViewController
orMapViewController
. Simple tab-bat approach. Does this container view controller require standalone ViewModel? If yes, does this view model correct: