在UIWebView完全加载后执行操作

时间:2012-07-30 18:18:00

标签: objective-c macos cocoa uiwebview

当WebView完全加载页面时,有没有办法让我运行一些代码? 这是我用来在视图中打开网页的代码,如果这有帮助的话。

//Load URL Into WebView
NSString *urlAddress = @"http://example.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[_listenupwebkit mainFrame] loadRequest:requestObj];

我的 .m 文件

- (IBAction)SignInButton:(id)sender {
//Load URL Into WebView

NSString *urlAddress = @"http://www.pandora.com/account/sign-in";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_listenupwebkit setFrameLoadDelegate:delegate];
[[_listenupwebkit mainFrame] loadRequest:requestObj];


loginbutton.hidden = YES;
webkithome.enabled = YES;



}

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame*)frame
{
    if(frame == [sender mainFrame]) {
        NSLog(@"viewDidLoad");
    }
}

我的 .h 文件

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame*)frame;
@end

1 个答案:

答案 0 :(得分:1)

提供

的实施
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame*)frame

frameLoadDelegate

[_listenupwebkit setFrameLoadDelegate:delegate];
[[_listenupwebkit mainFrame] loadRequest:requestObj];

在方法实现中,检查完成的帧是否是主帧:

 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame*)frame
 {
    if(frame == [sender mainFrame]) {