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

标签 objective-c ios xcode4

我正在以编程方式创建 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/

相关文章:

objective-c - 类和 block 的生命周期

ios - 更改 UITabBarController 中选项卡的顺序

xcode4 - 错误: failed to attach to process ID 0

ios - 将信息从 UITableViewDataSource 传递回 ViewController

Xcode 4 - Interface Builder 中是否有类似 "reveal in canvas"的内容?

ios - CoreData 与归档?

iphone - 将人员组添加到 ABAddressBookRef,组添加正常,但人员未添加到组?

ios - 如何使用 Skobbler 缩放到 map 上的当前位置

iphone - 第二次解析调用导致 NSXMLParser 内存泄漏

ios - 仅从表行弹出 Watchkit 上下文菜单?