我正在尝试加载 UIWebview 并尝试在加载 webview 时实现 SVProgress HUD,然后在加载时将其关闭。我几乎完成了它但是当它加载进度 hud 显示一秒钟然后再显示然后显示一秒钟和第四次,就像它闪烁我有点卡住了,看看我的代码。
在我的 .h 中:
#import <UIKit/UIKit.h>
#import "SVProgressHUD.h"
@interface ViewController2 : UIViewController <UIWebViewDelegate> {
//Instantiated the timer varibale inside the interface.
NSTimer *timer1;
IBOutlet UIWebView *webView;
}
//Instantiate the webview ans NSString link.
@property(nonatomic,retain) UIWebView *webView;
@property (strong, nonatomic) NSString *link;
在我的.m
#import "ViewController2.h"
@interface ViewController2 ()
@end
@implementation ViewController2
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Getting the link from the NSString called "link" and putting in the request.
NSString *link = [NSString stringWithString:self.link];
NSURL *URL = [NSURL URLWithString:link];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[webView loadRequest:request];
//Set the time for the loagind modal view.
timer1 = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];
//Webview Properties
//Webview's name is web, which was instantianted in the propeties section.
webView.ScalesPageToFit = true;
webView.backgroundColor = [UIColor pomegranateColor];
}
//When the UIWebview is loading present "Fetching Homework" alert, thanks to SVProgressHUD
-(void)loading {
if(!webView.loading)
[SVProgressHUD dismiss];
else
[SVProgressHUD showWithStatus:@"Loading Homework"];
}
我认为它可能只是计时器,但我不确定,任何帮助将不胜感激。
提前致谢。