1 #import2 3 @interface UITestViewController : UIViewController 4 { 5 6 } 7 8 @end 9 10 11 // 12 // UITestViewController.m 13 // UITest 14 // 15 16 #import "UITestViewController.h" 17 18 @implementation UITestViewController 19 20 - (void)viewDidLoad { 21 22 [super viewDidLoad]; 23 24 CGRect webRect = CGRectMake(10,10,300,400); 25 UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect]; 26 27 myWebView.delegate = self; 28 29 myWebView.scalesPageToFit = NO; 30 NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myPage" ofType:@"html"]; 31 NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 32 33 [myWebView loadHTMLString:htmlContent baseURL:nil]; 34 35 [self.view addSubview:myWebView]; 36 37 [myWebView release]; 38 } 39 40 - (BOOL)webView:(UIWebView *)webView 41 shouldStartLoadWithRequest:(NSURLRequest *)request 42 navigationType:(UIWebViewNavigationType)navigationType { 43 NSURL *pageURL = [request URL]; 44 45 if ( ([[pageURL scheme] isEqualToString: @"http"]) && (navigationType == UIWebViewNavigationTypeLinkClicked )) 46 { 47 [[UIApplication sharedApplication] openURL:pageURL]; 48 return NO; 49 } 50 51 return YES; 52 } 53 54 55 - (void)didReceiveMemoryWarning { 56 // Releases the view if it doesn't have a superview. 57 [super didReceiveMemoryWarning]; 58 59 // Release any cached data, images, etc that aren't in use. 60 } 61 62 - (void)viewDidUnload { 63 // Release any retained subviews of the main view. 64 // e.g. self.myOutlet = nil; 65 } 66 67 68 - (void)dealloc { 69 70 [super dealloc]; 71 } 72 73 @end