File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments