gpt4 book ai didi

objective-c - 使用委托(delegate)以编程方式创建 UIWebView

转载 作者:行者123 更新时间:2023-12-01 19:26:07 25 4
gpt4 key购买 nike

我正在以编程方式创建 UIWebView,但我需要触发此函数,以便在自定义 View 中打开 href:

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

//You might need to set up a interceptLinks-Bool since you don't want to intercept the initial loading of the content
if (interceptLinks) {
NSURL *url = request.URL;
//This launches your custom ViewController, replace it with your initialization-code
BrowserViewController *bv = [[BrowserViewController alloc] initWithUrl:url];
bv.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:bv animated:YES];
[bv release];
return NO;
}
//No need to intercept the initial request to fill the WebView
else {
interceptLinks = YES;
return YES;
}
}

如何将委托(delegate)链接到以编程方式创建的 UIWebView 以便函数触发?

最佳答案

您在上面所做的看起来是正确的。

只需在接口(interface)类和实现类上添加 UIWebViewDelegate 协议(protocol)
添加

webview.delegate = self;

所以你的 shouldStartLoadWithRequest 被调用。

关于objective-c - 使用委托(delegate)以编程方式创建 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7489369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com