@@ -747,6 +747,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
747
747
748
748
- (void )webView : (UIWebView *)webView didFailLoadWithError : (NSError *)error
749
749
{
750
+ self.loadingBarView .alpha = 0 .0f ;
750
751
[self handleLoadRequestCompletion ];
751
752
[self refreshButtonsState ];
752
753
}
@@ -767,11 +768,30 @@ - (void)forwardButtonTapped:(id)sender
767
768
768
769
- (void )reloadStopButtonTapped : (id )sender
769
770
{
770
- if (self.webView .isLoading )
771
- [self .webView stopLoading ];
772
- else
773
- [self .webView reload ];
771
+ // regardless of reloading, or stopping, halt the webview
772
+ [self .webView stopLoading ];
773
+
774
+ if (self.webView .isLoading ) {
775
+ // if we were loading, hide the load bar for now
776
+ self.loadingBarView .alpha = 0 .0f ;
777
+ }
778
+ else {
779
+ // In certain cases, if the connection drops out preload or midload,
780
+ // it nullifies webView.request, which causes [webView reload] to stop working.
781
+ // This checks to see if the webView request URL is nullified, and if so, tries to load
782
+ // off our stored self.url property instead
783
+ NSURLRequest *request = self.webView .request ;
784
+ if (self.webView .request .URL .absoluteString .length == 0 && self.url )
785
+ {
786
+ request = [NSURLRequest requestWithURL: self .url];
787
+ [self .webView loadRequest: request];
788
+ }
789
+ else {
790
+ [self .webView reload ];
791
+ }
792
+ }
774
793
794
+ // refresh the buttons
775
795
[self refreshButtonsState ];
776
796
}
777
797
@@ -1004,6 +1024,9 @@ - (void)resetLoadProgress
1004
1024
1005
1025
- (void )startLoadProgress
1006
1026
{
1027
+ if (self.webView .isLoading == NO )
1028
+ return ;
1029
+
1007
1030
// If we haven't started loading yet, set the progress to small, but visible value
1008
1031
if (_loadingProgressState.loadingProgress < kInitialProgressValue )
1009
1032
{
@@ -1051,9 +1074,6 @@ - (void)incrementLoadProgress
1051
1074
1052
1075
- (void )finishLoadProgress
1053
1076
{
1054
- // hide the activity indicator in the status bar
1055
- [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: NO ];
1056
-
1057
1077
// reset the load progress
1058
1078
[self refreshButtonsState ];
1059
1079
[self setLoadingProgress: 1 .0f ];
@@ -1152,6 +1172,15 @@ - (void)refreshButtonsState
1152
1172
[self .forwardButton setEnabled: YES ];
1153
1173
else
1154
1174
[self .forwardButton setEnabled: NO ];
1175
+
1176
+ if (self.webView .isLoading ) {
1177
+ [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: YES ];
1178
+ [self .reloadStopButton setImage: self .stopIcon forState: UIControlStateNormal];
1179
+ }
1180
+ else {
1181
+ [[UIApplication sharedApplication ] setNetworkActivityIndicatorVisible: NO ];
1182
+ [self .reloadStopButton setImage: self .reloadIcon forState: UIControlStateNormal];
1183
+ }
1155
1184
}
1156
1185
1157
1186
#pragma mark -
0 commit comments