永远不会调用shouldStartLoadWithRequest [英] shouldStartLoadWithRequest is never called

查看:129
本文介绍了永远不会调用shouldStartLoadWithRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究过并且仍然不明白为什么从未调用过StartLoadWithRequest。我的页面加载正常,并调用了一些UIWebview委托协议方法。请从下面的代码中找到相关的代码段:

I've researched and researched and still don't understand why shouldStartLoadWithRequest is never called. My page loads fine and some of the UIWebview delegate protocol methods are called. Please find relevant snippets from my code below:

在我的.m中合成我的webview(在头文件中定义):

Synthesize my webview in my .m (defined in a header file):

@implementation PortViewController

@synthesize WebView = myWebView;

我成功加载了我的网页视图:

I load my webview successfully:

    myURLString = [NSString stringWithFormat:@"https://%@", defaultWebsite];

    myURL = [NSURL URLWithString: myURLString];
    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
    [myWebView loadRequest:myRequest];

将我的代表设为自己

- (void)viewDidLoad
{


[super viewDidLoad];
[myWebView setOpaque:NO];
[myWebView setBackgroundColor:[UIColor clearColor]];

//myWebView.description.

myWebView.delegate = self;
}

我的所有协议方法都被称为EXCEPT shouldStartLoadWithRequest

all of my protocol methods are called EXCEPT shouldStartLoadWithRequest

- (void)webViewDidStartLoad:(UIWebView *)myWebView {
    [activityIndicator startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)myWebView {
    [activityIndicator stopAnimating];
}

- (BOOL)WebView:(UIWebView *)myWebView shouldStartLoadWithRequest:(NSURLRequest *)request          navigationType:(UIWebViewNavigationType)navigationType {

NSLog(@"inside Webview");
if([[request.URL absoluteString] hasPrefix:@"http://www.nzx"]) {
    // do stuff
    NSLog(@"Have caught the prefix");
    return YES;
}

    return NO;
}

提前致谢。

推荐答案

尝试在ViewWillAppear中设置委托而不是ViewDidLoad

Try setting the delegate in ViewWillAppear instead of ViewDidLoad

-(void)viewWillAppear:(BOOL)animated
{
     myWebView.delegate = self;
}

并在您的PortViewController.m文件界面中包含webview委托

and include the webview delegate in your interface of PortViewController.m file

@interface PortViewController ()<UIWebViewDelegate>


@end

它应该有效。

这篇关于永远不会调用shouldStartLoadWithRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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