我正在构建一个 iOS 应用。
我在带有超链接的 UIWebView 中有 HTML 内容,我无法打开指向另一个 UIWebView 的链接。
我使用 UIWebView 作为 ViewController 的 subview 。代码如下:
- (BOOL)webViewUIWebView *)webView shouldStartLoadWithRequestNSURLRequest *)request navigationTypeUIWebViewNavigationType)navigationType
{
switch (navigationType) {
case UIWebViewNavigationTypeLinkClicked: { //this is when a user tap is detected
//write the handling code here.
isWebViewLoaded = false; //set this to false only if you open another view controller.
return NO; //prevent tapped URL from loading inside the UIWebView.
}
// some other typical parameters within a UIWebView. Use what is needed
case UIWebViewNavigationTypeFormResubmitted: return YES;
case UIWebViewNavigationTypeReload: return YES;
//for all other cases, including UIWebViewNavigationTypeOther called when UIWebView is loading for the first time
default: {
if (!isWebViewLoaded) {
isWebViewLoaded = true;
return YES;
}
else
return NO;
}
}
}
Best Answer-推荐答案 strong>
您只需要使用 Web View 连接到新 Controller ,并将请求传递给它。所以在你的第一种情况下是这样的,
case UIWebViewNavigationTypeLinkClicked: { //this is when a user tap is detected
[self performSegueWithIdentifier"Next" sender:request];
isWebViewLoaded = false; //set this to false only if you open another view controller.
return NO; //prevent tapped URL from loading inside the UIWebView.
}
注意 performSegueWithIdentifier:sender: 中的 sender 参数是委托(delegate)方法返回的请求。将此请求传递给您要转到的 View Controller 中的属性,
-(void)prepareForSegueUIStoryboardSegue *)segue senderNSURLRequest *)sender {
NextViewController *next = segue.destinationViewController;
next.request = sender;
}
最后,使用该请求在 NextViewController 中加载 Web View 。
关于ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/24635107/
|