gpt4 book ai didi

ios - ReactiveCocoa捕捉到错误后,按钮信号不再被触发

转载 作者:行者123 更新时间:2023-12-01 20:07:22 25 4
gpt4 key购买 nike

如果我将UIControlEventTouchUpInside信号添加到doneButton,并调用API,如果API失败,则会调用catch。但是,如果我尝试再次单击按钮,则不会触发按钮控制事件。

- (void)viewDidLoad {
[super viewDidLoad];

[[[[[self.doneButton rac_signalForControlEvents:UIControlEventTouchUpInside] doNext:^(id x) {
[SVProgressHUD show];
}] flattenMap:^RACStream *(id value) {
return [[HttpService sharedService] updateImageData:UIImageJPEGRepresentation(self.signatureImageView.image, 0.5)];
}] catch:^RACSignal *(NSError *error) {
[SVProgressHUD showErrorWithStatus:error.localizedDescription];
return [RACSignal empty];
}] subscribeNext:^(id x) {
[SVProgressHUD dismiss];
[self.navigationController popToRootViewControllerAnimated:YES];
}];
}

最佳答案

我认为该线程会有所帮助。 https://github.com/ReactiveCocoa/ReactiveCocoa/issues/1218

如果信号失败/错误,则将自动取消订阅该信号。您可以使用- retry,但是这将继续尝试操作,直到不会失败为止,如果存在永久性问题,它将无限期循环。

将这种情况包装在flattenMap中将捕获问题,而无需取消订阅最初的rac_signalForControlEvents观察值。

在GitHub上面的线程中查看 mdiep 的评论,也许可以做类似的事情。

[[[[self.doneButton rac_signalForControlEvents:UIControlEventTouchUpInside] doNext:^(id x) {
[SVProgressHUD show];
}] flattenMap:^RACStream *(id value) {
return [[[HttpService sharedService] updateImageData:UIImageJPEGRepresentation(self.signatureImageView.image, 0.5)]
catch:^RACSignal *(NSError *error) {
[SVProgressHUD showErrorWithStatus:error.localizedDescription];
return [RACSignal empty];
}];
}] subscribeNext:^(id x) {
[SVProgressHUD dismiss];
[self.navigationController popToRootViewControllerAnimated:YES];
}];

我实际上并未使用此代码构建测试。只是根据 HttpService类中的内容进行猜测。

关于ios - ReactiveCocoa捕捉到错误后,按钮信号不再被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com