English 中文(简体)
UIWebView-方案未知
原标题:UIWebView - Scheme unknown

我需要一些帮助来处理UIWebView中的一些NSData对象。点击<code>UIWebView</code>中的链接会导致<code>NSLog</code〕条目:

Scheme unkown, doing nothing: <URL>

我就是这么做的:

我启动一个外部HTTPGetOperation来获得URL请求的响应。我需要这样做是因为处理下载文件。响应存储在NSData对象中。

然后,我在HTTPGetOperation完成时调用的方法中加载该数据:

[myWebView loadData:myNSDataObject MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

到目前为止,UIWebView正确显示了myNSDataObject的内容。

但是,当我尝试点击该内容中的链接时,我会得到一个NSLog条目“未知方案,无所事事:”,其中包含链接的URL。

注意:点击链接后,不会调用委托方法,如-webView:shouldStartLoadWithRequest:navigationType:

注意:委托设置为[self.myWebView setDelegate:self]

哪些方法创建NSLog条目?

为什么在点击链接后不调用委托方法?

有人知道答案吗?

问题回答

链接是如何编码的?它们是http://links还是自定义的?只要链接是标准形式的,shouldStartLoadWithRequest方法就可以测试URL方案,以确定应该如何处理它。

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, frame.size.width, frame.size.height - 44.0f)];
webView.delegate = self;

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] scheme] isEqualToString:@"mycustomdata"]) {
        // insert your code here to actually load the correct data
        return NO;
    }
}

如果您的代表没有接到电话,那么您还有其他问题。我还建议实现didFailLoadWithError、webViewDidFinishLoad和webViewDidStartLoad。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签