所以我在UIButton上使用RACCommand。点击此按钮后,用户注册即开始。它看起来像:
self->_termsOfServicesAcceptButton.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
UserModel* newUser = [[UserModel alloc] initWithUsername:self->_userNameTextField.text password:self->_passwordTextField.text email:self->_emailTextField.text firstname:self->_firstNameTextField.text lastname:self->_lastNameTextField.text];
return [self termsOfServicesAcceptedSignal:newUser];
}
状态指示器挂钩executing
信号,如:
[[self->_termsOfServicesAcceptButton.rac_command.executing deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNumber* isSigningUp) {
@strongify(self);
if ([isSigningUp boolValue]) {
[self->_signUpActivityIndicator startAnimating];
NSLog(@" activity indicator started animating");
}
else {
[self->_signUpActivityIndicator stopAnimating];
NSLog(@" activity indicator stopped animating");
}
}];
termsOfServicesAcceptedSignal
只是现有函数的包装器,如下所示:
RACSignal* signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[self termsOfServicesAcceptButtonPressed:newUser withCompletion:^{
[subscriber sendNext:@(YES)];
[subscriber sendCompleted];
}];
return nil;
}];
return signal;
好的,所以这很好用。现在,我想使用之前的newUserModelSignal
结果来传递UserModel信息,而不是从textField.text
读取它。我试过了:
self->_termsOfServicesAcceptButton.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [newUserModelSignal flattenMap:^RACStream *(UserModel* newUser) {
return [self termsOfServicesAcceptedSignal:newUser];
}];
}];
在这种意义上,newUser
正确传递,注册成功,但状态指示器永远不会停止旋转,即它永远不会收到任何结束的消息。
我收集它是因为使用替换代码,RACCommand不再自动订阅termsOfServicesAcceptedSignal
而是newUserModelSignal
。那么我该如何解决这个问题,以便状态指示器正确地拾取executing
信号?感谢。