【问题标题】:Performing a Segue in webView shouldStartLoadWithRequest and returning 'NO'在 webView shouldStartLoadWithRequest 中执行 Segue 并返回“NO”
【发布时间】:2012-09-13 13:58:22
【问题描述】:

我有一个加载带有 html 按钮的页面的 UIWebView。当用户点击该按钮时,会加载“http://somerequest”。

我在 shouldStartLoadWithRequest 中捕获请求(在下面的代码中),当请求“http://somerequest”时,使用标识符“Comments”执行 segue:

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

    NSURL *url = [request URL];


    if([[url absoluteString] isEqualToString:@"http://somerequest"])
    {

        [self performSegueWithIdentifier:@"Comments" sender:self];

        return NO;
    }
    return YES;
}

“performSegueWithIdentifier”工作正常,但 shouldStartLoadWithRequest 函数未返回“NO”。如果我删除“performSegueWithIdentifier”,该函数能够返回 NO。

请告诉我当 UIWebView 请求“http//somerequest”并且未在当前 UIWebView 中加载请求(通过返回“NO”)时如何执行 segue。

【问题讨论】:

    标签: objective-c ios uiwebview segue


    【解决方案1】:

    试试这个:

      - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    
        NSURL *url = [request URL];
        BOOL returnValue = YES;
    
        if([[url absoluteString] isEqualToString:@"http://somerequest"])
        {
    
            [self performSegueWithIdentifier:@"Comments" sender:self];
    
            returnValue =  NO;
        }
    
    
        return returnValue;
    }
    

    任何方式设置断点以确保'returnValue = NO;'叫做。 沙尼

    【讨论】:

    • 不工作。每当调用 [self performSegueWithIdentifier:@"Comments" sender:self] 时,函数返回 YES;
    • 您是否设置了断点以确保“返回 YES;”没有被调用?
    • 你的回答是正确的,这实际上是我遇到的一些 jQuery 移动相关问题。
    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多