我正在尝试从我的类加载UIWebview,这里是它的testClass.h文件
#import <UIKit/UIKit.h>
@interface testClass : UIView<UIWebViewDelegate>
@property(nonatomic,retain) UIViewController *superObj;
- (void) showView;
@end
下面是testClass.m的代码,superObj是Contrller从中分配的自我的主要视图。
@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控件时,不应该使用StartLoadWithRequest方法。我无法理解为什么这不起作用。
从文档中:
webView:shouldStartLoadWithRequest:navigationType:
返回值
是的,如果 Web 视图应该开始加载内容;否则,否 .