Voglio sapere come implementare un'attivitàIndicatore in un'applicazione basata su WebView, ho scritto il seguente codice ma l'indicatore non viene visualizzato.Come implementare UIActivityIndicatorView quando UIWebView sta caricando? (iPhone ObjC)
Il file di caricamento WebView a livello locale, in modo da caricare molto veloce, ma quando si carica una pagina esterna si caricherà lentamente e ho bisogno l'indicatore ...
FirstViewController.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
FirstViewController.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");
}
Non è necessario disattivarlo anche nel metodo 'didFailLoadWithError'? –