The way I’ve been doing it for a few years is to simply create two toolbars, and set one or the other to hidden while the UIWebView loads. All of my toolbars and barbutton items are created in IB. I would like to make my implementation smaller if I can without this sort of “hack” I appreciate any help offered.
Here is the code I’m using:
#import "Web.h"
@interface Web()
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *refreshButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *stopButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *backButtonRefreshToolbar;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *forwardButtonRefreshToolbar;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *backButtonStopToolbar;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *forwardButtonStopToolbar;
@property (nonatomic, strong) IBOutlet UIToolbar *toolbarStop;
@property (nonatomic, strong) IBOutlet UIToolbar *toolbarRefresh;
@end
@implementation Web
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.toolbarStop.hidden = NO;
self.toolbarRefresh.hidden = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
self.toolbarStop.hidden = YES;
self.toolbarRefresh.hidden = NO;
[self actualizeButtons];
}
- (void)actualizeButtons
{
self.backButtonRefreshToolbar.enabled = [self.webView canGoBack];
self.forwardButtonRefreshToolbar.enabled = [self.webView canGoForward];
self.backButtonStopToolbar.enabled = [self.webView canGoBack];
self.forwardButtonStopToolbar.enabled = [self.webView canGoForward];
}
This is what I came up with based on the above help: