1

我有一个 webview 和 3 个 url。

因此,当应用程序启动时,我在 webview 中显示 URL1。

现在,当我选择 webview 的任何部分时,它将重定向到 URL2。

但只有我想从 URL2 获取一些数据并且不想将其显示给用户。

我可以通过使用 shouldStartLoadWithRequest: 返回 NO 的方法来做到这一点。

但现在我需要在我的 Webview 中显示从 URL2 接收到的数据的 URL 3。

但它没有显示任何东西,我该怎么做?

为此,我使用以下代码

-(void)viewDidLoad
{
//Normal showing of URL1 in webview

}

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

//get data from URL2
//Make New URL3 string
[webView loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:myNewUrlString]]];
return NO;
}
else
{
//by default URL1 comes 
return YES;
}
4

2 回答 2

1

我这样做了:

我试图通过 GET 方法发送信息,所以我将任何请求的 url 的最后 10 个字符(在我的情况下)子串,如果它没有 GET 方法,它会发出一个新请求,将 GET 方法附加到 url 和返回 NO,下次调用此函数时,它将具有 GET 方法,因此它将继续。

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

NSString *urls = [request.URL absoluteString];
NSString *code = [urls substringFromIndex: [urls length] - 10];

if (![code isEqualToString:@"?iphone=si"]) {
    NSURL *nueva = [NSURL URLWithString:[NSString stringWithFormat:@"%@?iphone=si",urls]];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:nueva];
    [self.mywebview loadRequest:requestObj];
    return NO;
}
return YES;
}
于 2013-12-10T01:58:39.140 回答
-1

我就是这样做的

                NSURL *LocalUrl = [[NSURL alloc] initWithString:[newUrl stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]];

                NSURLRequest *objNSURLRequest;

                objNSURLRequest = [NSURLRequest requestWithURL:LocalUrl];

                [yourwebview loadRequest:ObjNSURLRequest];

                [LocalUrl release];

                return NO;
于 2012-08-24T07:01:04.307 回答