我是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
答案 0 :(得分:1)
@interface
// declare a loading indicator
@property (strong, nonatomic) UIActivityIndicatorView*loadingIndicator;
- (void)viewDidLoad {
self.webview.delegate = (id<UIWebViewDelegate>)[self class];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.center = self.webview.center;
[activityIndicator setHidden:YES];
self.loadingIndicator=activityIndicator;
[self.view addSubview:self.loadingIndicator];
[super viewDidLoad];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[self.loadingIndicator startAnimating] ;
[self.loadingIndicator setHidden:NO];
}
-(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] ;
}
我认为你正在寻找这个,不好意思..
答案 1 :(得分:1)
在视图中显示活动指示器并将其放在屏幕中心或webview.Default隐藏活动指示器。
现在,当你加载webPage然后显示活动指示器,直到你的网页完全加载。
-(void)webViewDidFinishLoad:(UIWebView *)webView1{
if (webView1.isLoading){
return;
}
[self.activityView stopAnimating];
self.activityView.hidden = TRUE;
}