I would create a new subclass of the UIViewController class, say WebViewController using nib. Then I will add a UINavigationBar with a close button and a UIWebView . Then, to show your webview controller, you can do something like:
WebViewController *webViewController = [[WebViewController alloc] init]; webViewController.loadURL = [NSURL URLWithString:@"http://www.google.com"]; [self presentModalViewController:webViewController animated:YES]; [webViewController release];
In WebViewController you can define:
@property (nonatomic, retain) IBOutlet UIWebView *webView; @property (nonatomic, retain) NSURL *loadURL; - (IBAction)close:(id)sender;
and implement something like this:
- (void)viewDidLoad { [super viewDidLoad] NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.loadURL]; [self.webView loadRequest:urlRequest]; } - (IBAction)close:(id)sender { [self dismissModalViewControllerAnimated:YES]; }
source share