我正在尝试从我的班级加载 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 方法。我无法理解为什么这不起作用。