Skip to content

Commit 8faf5f2

Browse files
committed
Add content
1 parent 74b906f commit 8faf5f2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

chapter6/mvvm_in_practice.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,51 @@ self.title = [self.viewModel.initialPhotoModel photoName];
262262
相当简单吧,我们来看一下我们新的`viewDidLoad`方法:
263263

264264
```Objective-C
265+
- (void)viewDidLoad {
266+
[super viewDidLoad];
267+
268+
//Configure self's view
269+
self.view.backgroundColor = [UIColor blackColor];
270+
271+
//Configure subViews
272+
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
273+
RAC(imageView, image) = RACObserve(self.viewModel,photoImage);
274+
imageView.contentModel = UIViewContentModelScaleAspectFit;
275+
[self.view addSubView:imageView];
276+
self.imageView = imageView;
277+
278+
[RACObserve(self.viewModel, loading) subscribeNext:^(NSNumber *loading) {
279+
if(loading.boolValue) {
280+
[SVProgressHUD show];
281+
}
282+
else {
283+
[SVProgressHUD dismiss];
284+
}
285+
}];
286+
}
265287

288+
```
289+
该图片视图的图片属性的绑定是标准的ReactiveCocoa方式,有趣的是下面(我们要提到的)我们使用`loading`的时刻。当加载信号发送`YES`的时候我们展示进度HUD,发送`NO`的时候,让进度HUD消失。我们将看到该`loading`信号本身如何依赖于`didBecomeActiveSignal`。现在只是视图模型通过网络请求获取图像数据的序幕。
290+
291+
接口的申明如下:
292+
293+
```Objective-C
294+
@class FRPPhotoModel;
295+
296+
@interface FRPPhotoViewModel : RVMViewModel
297+
298+
@property (nonatomic, readonly) FRPPhotoModel *model;
299+
@property (nonatomic, readonly) UIImage *photoImage;
300+
@property (nonatomic, readonly, getter = isLoading) BOOL loading;
301+
302+
- (NSString *)photoName;
303+
304+
@end
266305

267306
```
268307
269308
270309
271310
311+
312+

0 commit comments

Comments
 (0)