我想知道如何在基于 WebView 的应用程序中实现 activityIndicator,我编写了以下代码,但指标没有出现。
webview在本地加载文件,因此加载速度非常快,但是当它加载外部页面时加载速度很慢,我需要指示器...
第一视图控制器.h
#import <UIKit/UIKit.h>
@interface FirstViewController :
UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *webview1;
NSURL *urlLocation;
IBOutlet UIActivityIndicatorView *m_activity;
}
@property (nonatomic, retain) UIActivityIndicatorView *m_activity;
- (IBAction)searchbutton:(id)sender;
- (IBAction)home:(id)sender;
@end
第一视图控制器.m
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize m_activity;
// viewWillAppear loads every time younopen up this View
- (void)viewWillAppear:(BOOL)animated {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
urlLocation = [NSURL fileURLWithPath:filePath];
[webview1 loadRequest:[NSURLRequest requestWithURL:urlLocation]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//Initialization code
m_activity = nil;
}
return self;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
m_activity.hidden= TRUE;
[m_activity stopAnimating];
NSLog(@"Web View started loading...");
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
m_activity.hidden= FALSE;
[m_activity startAnimating];
NSLog(@"Web View Did finish loading");
}