我是 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
最佳答案
在您的 View 中获取事件指示器并将其放置在屏幕或 WebView 的中心。默认隐藏事件指示器。
现在,当您加载网页时,会显示事件指示器,直到您的网页完全加载。
-(void)webViewDidFinishLoad:(UIWebView *)webView1{
if (webView1.isLoading){
return;
}
[self.activityView stopAnimating];
self.activityView.hidden = TRUE;
关于ios - 添加进度对话框,在 iOS 的 webview 上显示加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27738797/