I currently have the following code that loads a UIWebView from another View. Now is there anyway I can have a close button?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:webView];
NSURLRequest *urlRequest;
NSURL *urlforWebView;
urlforWebView=[NSURL URLWithString:@"http://www.google.com"];
urlRequest=[NSURLRequest requestWithURL:urlforWebView];
[webView loadRequest:urlRequest];
}
I am going to load a page built using jquery mobile, so a close button inside the page would also work fine. But on a navigation bar would be ideal. Btw, my application does not have a UINavigationBar
Whenever you load the UIWebView, you could run a javascript snippet on the content first.
That just hijacks the normal behavior of
window.close()
and gives you chance to catch the call in your Objective-C.Then in your UIWebViewDelegate you could listen for whatever you chose as the close url.
A bit hackish, but it would allow the web developer to control the look and feel of the close button from within the HTML content.
I would create a new sub class of
UIViewController
, sayWebViewController
with a nib. Then I would add anUINavigationBar
with a close button and anUIWebView
. Then to show your web view controller you can do something like:In your
WebViewController
you can define:and implement something like this: