Hello, I seem to be stuck on two problems, the first one being that my activityIndicator is not working at all, and the second problem is that I'm trying to combine the stop and refresh buttons into one button for a cleaner design. Any help is truly appreciated! Here is a screenshot and my code:
Test.h:
and Test.m:

Test.h:
Code:
#import <UIKit/UIKit.h>
@interface Test : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
UIBarButtonItem *refreshButton;
UIBarButtonItem *backButton;
UIBarButtonItem *forwardButton;
UIBarButtonItem *stopButton;
UIActivityIndicatorView *activityIndicator;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *refreshButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *backButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *forwardButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *stopButton;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
-(IBAction)refreshWebView;
-(IBAction)goBack;
-(IBAction)goForward;
-(IBAction)stop;
-(void)actualizeButtons;
@end
and Test.m:
Code:
#import "Test.h"
@implementation Test
@synthesize webView;
@synthesize activityIndicator;
@synthesize refreshButton;
@synthesize backButton;
@synthesize forwardButton;
@synthesize stopButton;
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown);
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Test";
NSString *urlAddress = @"https://www.macrumors.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
-(void)actualizeButtons {
backButton.enabled = [webView canGoBack];
forwardButton.enabled = [webView canGoForward];
}
-(IBAction)refreshWebView {
[webView reload];
}
-(IBAction)stop {
[webView stopLoading];
}
-(IBAction)goBack {
[webView goBack];
[self actualizeButtons];
}
-(IBAction)goForward{
[webView goForward];
[self actualizeButtons];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[activityIndicator stopAnimating];
stopButton.enabled = NO;
refreshButton.enabled = YES;
[self actualizeButtons];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
stopButton.enabled = NO;
refreshButton.enabled = YES;
[self actualizeButtons];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating];
stopButton.enabled = YES;
refreshButton.enabled = NO;
[self actualizeButtons];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
[refreshButton release];
[backButton release];
[forwardButton release];
[stopButton release];
[activityIndicator release];
[webView release];
}
@end