如何查找UIWebView的最后一次加载(Ready State 4) [英] How to find last load of UIWebView(Ready State 4)

查看:98
本文介绍了如何查找UIWebView的最后一次加载(Ready State 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIWebView 中的 didFinishLoad 方法遇到问题。我想尝试一下estimatedProgress 解决方案,不过我不知道在哪里不幸的是找到那些框架。我正在运行Mountain Lion并使用最新版本的XCode。此外,对于多次触发的UIWebView,这是最好的方法还是有新的方法。似乎有关于SO的javascript 回答,但这对我不起作用。这可以追溯到2009年,我听说苹果公司拒绝任何使用私有API的应用程序。请帮帮我吧!

I have a problem with the didFinishLoad method in UIWebView that is keeps firing. I want to try the estimatedProgress solution, however I dont know where to find those frameworks unfortunately. I am running Mountain Lion and using the latest version of XCode. Also, for the UIWebView firing multiple times, is this the best way to go or are there new methods. There seems to be a javascript answer on SO, however that did not work for me. That was dated back in 2009, and I hear that Apple rejects any app that uses a private API. Please help me out here!

谢谢大家!

推荐答案

什么关于跟踪未完成请求的数量?我发布了一些似乎有用的测试代码:

What about keeping track of the number of outstanding requests? I whipped up some test code that seems to work:

@interface WebViewDelegate : NSObject<UIWebViewDelegate>
@property ( nonatomic ) NSUInteger numberOfRunningRequests ;
@end

@implementation WebViewDelegate

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    self.numberOfRunningRequests = self.numberOfRunningRequests + 1 ;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.numberOfRunningRequests = self.numberOfRunningRequests - 1 ;
    if ( self.numberOfRunningRequests == 0 )
    {
        NSLog(@"done!\n") ;
    }
}

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    UIWebView * webView = [[ UIWebView alloc ] initWithFrame:self.window.bounds ] ;
    static WebViewDelegate * delegate = nil ;
    delegate = [[ WebViewDelegate alloc ] init ] ;
    webView.delegate = delegate ;

    [self.window addSubview:webView ] ;
    NSURLRequest * request = [ NSURLRequest requestWithURL:[ NSURL URLWithString:@"http://stackoverflow.com"] ];
    [ webView loadRequest:request ] ;
    return YES;
}

@end

(创建Xcode示例项目并用此替换您的AppDelegate.m)

(Create an Xcode sample project and replace your AppDelegate.m with this)

这篇关于如何查找UIWebView的最后一次加载(Ready State 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆