活动指标问题? (SVProgressHUD)

时间:2013-08-21 22:05:43

标签: objective-c uiactivityindicatorview

我正在尝试加载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"];
}

我认为它可能只是计时器,但我不确定,任何帮助都会受到高度赞赏。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您应该使用Web视图委托知道页面何时结束加载,而不是使用计时器每0.5秒检查一次。试试这种方式:

在页面加载

时开始SVProgressHUD
     [SVProgressHUD showWithStatus:@"Loading Homework"];  

然后在页面加载完毕后将其删除。

  - (void)webViewDidFinishLoad:(UIWebView *)webView {
        [SVProgressHUD dismiss];
    }

不要忘记您还必须将webview委托设置为:

     webView.delegate = self;