So I have this BaseCell
class which also has this BaseCellViewModel
. Of course on top of this lives some FancyViewController
with FancyViewModel
. The case here is that BaseCell
has UIButton
on it which triggers this IBAction
method - that's fine and that's cool as I can do whatever I want there, but... I have no idea how should I let know FacyViewController
about the fact that some action happened on BaseCell
.
I can RACObserve
a property in FancViewModel
as it has NSArray
of those cell view models, but how to monitor actual action and notify about exact action triggered on cell?
First thing that came to my mind is the delegation or notifications, but since we have RAC in our project it would be totally stupid not to use it, right?
[Edit] What I did so far...
So, it turns out youc can use RACCommand
to actually handle UI events on specific button. In that case I've added:
@property (strong, nonatomic) RACCommand *showAction;
to my BaseCellViewModel
with simple implementation like:
- (RACCommand *)showAction {
return [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
NSLog(@"TEST");
return [[RACSignal empty] logAll];
}];
}
And following this pattern I had to do something in my BaseCell
which turned out to be quite simple and I ended up with adding:
- (void)configureWithViewModel:(JDLBasePostCellViewModel *)viewModel {
self.viewModel = viewModel;
self.actionButton.rac_command = self.viewModel.showAction;
}
And... It works! But...
I need to present UIActionSheet
whenever this happens and this can be show only when I need the current parentViewController
and since I don't have this kind of information passed anywhere I don't know what to do right now.
FancyViewModel
holds a private @property (nonatomic, strong) NSMutableArray <BaseCellViewModel *> *cellViewModels;
, but how can I register something on FancyViewController
to actually listen for execution of RACCommand
on BaseCellViewModel
?