美文网首页
结合加载视图使用

结合加载视图使用

作者: csp | 来源:发表于2017-06-23 22:04 被阅读17次

[RACObserve(self.viewModel, loading) subscribeNext:^(NSNumber *loading){
if (loading.boolValue) {
[SVProgressHUD show];
} else {
[SVProgressHUD dismiss];
}
}];
绑定loading属性,YES的时候加载视图出现,NO的时候家在视图消失。

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

self.viewModel.active = YES;

}

-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];

self.viewModel.active = NO;

}
有active属性;
使用这个属性需要Model继承自RVMViewModel。

@weakify(self);
[self.didBecomeActiveSignal subscribeNext:^(id x) {
@strongify(self);
[self downloadPhotoModelDetails];
}];

-(void)downloadPhotoModelDetails {
self.loading = YES;

@weakify(self);
[[FRPPhotoImporter fetchPhotoDetails:self.model] subscribeError:^(NSError *error) {
    NSLog(@"Could not fetch photo details: %@", error);
} completed:^{
    @strongify(self);
    self.loading = NO;
    NSLog(@"Fetched photo details.");
}];

}

相关文章

网友评论

      本文标题:结合加载视图使用

      本文链接:https://www.haomeiwen.com/subject/qokhcxtx.html