ios - Disabling UIBarButtonItem with ReactiveCocoa -


i'm trying disable uibarbuttonitem in ios app when condition has been met.

so in viewmodel created signal:

-(racsignal *)thresholdlimitreachedsignal {     @weakify(self);     return [racobserve(self, thresholdlimitreached) filter:^bool(id value) {             @strongify(self);         return self.thresholdlimitreached;     }]; } 

then in viewcontroller have this:

self.requestnewpinbutton.rac_command = [[raccommand alloc]initwithenabled:self.viewmodel.thresholdlimitreachedsignal                                                                    signalblock:^racsignal *(id input) {             [self.viewmodel.requestnewpinsignal subscribenext:^(id x) {                     //do stuff here            }];            return [racsignal empty];        }]; 

so uibarbuttonitem triggered , fires off requestnewpinsignal works fine. flag thresholdlimitreached causes thresholdlimitreachedsignal fire - good. button not disabled , not sure why? no matter if manually set boolean true or false inside thresholdlimitreachedsignal method - button remains enabled!

if manually subscribe thresholdlimitreachedsignal so:

[self.viewmodel.thresholdlimitreachedsignal subscribenext:^(id x) {     self.requestnewpinbutton.enabled = no; }]; 

then button gets disabled no problem. i'd have signal combined requestsignal how - thought initwithenabled:signalblock did this?

would appreciate help! thanks!

[racobserve(self, thresholdlimitreached) filter:^bool(id value) {         @strongify(self);     return self.thresholdlimitreached; }]; 

you're filtering thresholdlimitreachedsignal ever returns yes, button going enabled. starters, rewrite , avoid @weakify/@strongify:

[racobserve(self, thresholdlimitreached) filter:^bool(nsnumber *thresholdlimitreached) {     return thresholdlimitreached.boolvalue; }]; 

but don't that: if you're using enabled signal, needs signal of booleans sends yes when should enabled , no when should disabled.

assuming want button disabled when threshold has been reached, want this:

[[raccommand alloc] initwithenabled:[racobserve(self.viewmodel, thresholdlimitreached) not]                         signalblock:...]; 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -