diff --git a/Blog/Base.lproj/Main.storyboard b/Blog/Base.lproj/Main.storyboard index 20a6fd7..88b2c78 100644 --- a/Blog/Base.lproj/Main.storyboard +++ b/Blog/Base.lproj/Main.storyboard @@ -321,18 +321,23 @@ wanted with as little input and thought as possible. - + + + + + + @@ -342,6 +347,7 @@ wanted with as little input and thought as possible. + @@ -480,6 +486,6 @@ wanted with as little input and thought as possible. - + diff --git a/Blog/PreviewViewController.m b/Blog/PreviewViewController.m index d67a50a..7cb4096 100644 --- a/Blog/PreviewViewController.m +++ b/Blog/PreviewViewController.m @@ -11,6 +11,7 @@ @interface PreviewViewController () @property (nonatomic, weak) IBOutlet UIWebView *webView; +@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *indicatorView; @end @@ -22,40 +23,42 @@ // UIWebView restores its request so we just have to reload it if (!self.initialRequest && self.webView.request) { [self.webView reload]; + [self.indicatorView startAnimating]; return; } if (self.initialRequest) { - if (self.promise) { - __weak typeof(self) welf = self; - self.promise.then(^{ - typeof(self) self = welf; - [self.webView loadRequest:self.initialRequest]; - }).finally(^{ - typeof(self) self = welf; - self.promise = nil; - }); - return; - } - [self.webView loadRequest:self.initialRequest]; + PMKPromise *p = self.promise ?: [PMKPromise promiseWithValue:nil]; + __weak typeof(self) welf = self; + p.then(^{ + typeof(self) self = welf; + [self.webView loadRequest:self.initialRequest]; + [self.indicatorView startAnimating]; + }).finally(^{ + typeof(self) self = welf; + self.promise = nil; + }); return; } } - (void)setInitialRequest:(NSURLRequest *)initialRequest { _initialRequest = initialRequest; - [self.webView loadHTMLString:@"" baseURL:nil]; + self.webView.hidden = YES; } #pragma mark - UIWebViewDelegate methods - (void)webViewDidFinishLoad:(UIWebView *)webView { + self.webView.hidden = NO; + [self.indicatorView stopAnimating]; if ([webView.request.URL isEqual:self.initialRequest.URL]) { self.initialRequest = nil; } } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { + [self.indicatorView stopAnimating]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert]; __weak typeof(self) welf = self; [alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {