【发布时间】:2015-01-02 19:56:15
【问题描述】:
我是 iOS 开发的新手。有什么方法可以在 webview 上显示一个进度对话框,该对话框在页面加载时显示加载页面并在页面加载后关闭。
请推荐一些好的教程
提前致谢
这是我正在做的代码,但没有显示
@interface ViewController ()
@property (strong, nonatomic) UIActivityIndicatorView*loadingIndicator;
@end
@implementation ViewController
@synthesize myWebview;
- (void)viewDidLoad {
self.myWebview.delegate = (id<UIWebViewDelegate>)[self class];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = self.myWebview.center;
[activityIndicator setHidden:YES];
self.loadingIndicator=activityIndicator;
[self.view addSubview:self.loadingIndicator];
NSURL *url=[NSURL URLWithString:@"http://getaservice.pk/joomla"];
self.myWebview.delegate = (id<UIWebViewDelegate>)[self class];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[myWebview loadRequest:request];
[super viewDidLoad];
}
// Do any additional setup after loading the view, typically from a nib.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
[self.loadingIndicator startAnimating] ;
[self.loadingIndicator setHidden:NO];
return YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[self.loadingIndicator setHidden:YES];
[self.loadingIndicator stopAnimating] ;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self.loadingIndicator setHidden:YES];
[self.loadingIndicator stopAnimating] ;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)button:(id)sender {
}
@end
【问题讨论】: