从UIWebview委托方法在Safari浏览器中无法打开URL

时间:2012-12-04 15:59:33

标签: ios uiwebview xcode4.5

我正在尝试从我的类加载UIWebview,这里是它的testClass.h文件

#import <UIKit/UIKit.h>
@interface testClass : UIView<UIWebViewDelegate>

@property(nonatomic,retain) UIViewController *superObj;
- (void) showView;
@end

以下是testClass.m的代码,superObj是一个主要的viewContrller自己分配的。

@synthesize superObj; //assigned from viwController as self 
- (void)showView {
    CGRect firstRect = CGRectMake(0, 0, 100.0, 50.0);
    UIWebView *webView = [[UIWebView alloc] initWithFrame:firstRect];
    webView.delegate = self;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/inapp/index.php"]]];
    [superObj.view addSubview:webView];
}

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

    NSLog(@"In delegate method");
   if ([[[request URL] absoluteString] isEqual:@"http://localhost/inapp/index.php"])
        return YES;    
   [[UIApplication sharedApplication] openURL:[request URL]];//opens url in safari
   return NO;
}

这是能够显示UIWebview并在其中呈现html,但是当我点击url控件时不会使用shouldStartLoadWithRequest方法。我无法理解为什么这不起作用。

1 个答案:

答案 0 :(得分:0)

来自文档:

<强> web视图:shouldStartLoadWithRequest:navigationType:

返回值
如果Web视图应该开始加载内容,则为YES;否则,没有。

相关问题