我有UIWebView
代表id<UIWebViewDelegate>
。当我点击UIWebView中的链接时,我在回调中得到NSURLRequest
对象:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
我要做的是:
- (void)presentWebViewControllerWithUrl:(NSURL*)URL{
SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithURL:URL];
webViewController.modalPresentationStyle = UIModalPresentationPageSheet;
webViewController.availableActions = SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsCopyLink | SVWebViewControllerAvailableActionsMailLink;
[self presentModalViewController:webViewController animated:YES];
}
当我将此代码放在我的主视图控制器中时,会出现模态Web视图,但如果我将它放在我的委托中则不会。如何让它出现?
从NO
返回shouldStartLoadWithRequest
只会让我的UIWebView变为白色,没有任何内容。似乎在webviews加载时调用了回调。我使用HTML
将本地存储的[web loadHTMLString:@"..." baseUrl: nil]
加载到其中
模态永远不会出现。
我的视图层次结构如下:
有没有办法“冒泡”回调,以便我可以在主视图控制器中看到该事件?
答案 0 :(得分:0)
确保在覆盖shouldStartLoadWithRequest委托方法时返回(NO)。
另外,我没有在你的代码中看到[viewController presentModalViewController:webViewController animated:YES],如下所示:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType != UIWebViewNavigationTypeLinkClicked)
return (YES);
SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithURL:[request URL]];
webViewController.modalPresentationStyle = UIModalPresentationPageSheet;
webViewController.availableActions = SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsCopyLink | SVWebViewControllerAvailableActionsMailLink;
[myViewController presentModalViewController:webViewController animated:YES];
return(NO);
}