1

I wonderd if there is any way to make the user dismiss the WebView window if he doesn't want it anymore on the screen...? I looked at this post but i didn't understand it well. How to cancel a UIWebView? can anyone give me an example please? This is the code i have:

CGSize webScreen1;
webScreen1 = [[UIScreen mainScreen] applicationFrame].size;
CGRect webFrame1 = CGRectMake((webScreen1.width/11.0) ,(webScreen1.height/19.0)  ,webScreen1.width/1.2,webScreen1.height/1.25);
defaultWebView.frame = webFrame1;
self.defaultWebView = [[UIWebView alloc] initWithFrame:webFrame1];
self.defaultWebView.backgroundColor = [UIColor whiteColor];
self.defaultWebView.scalesPageToFit = YES;
self.defaultWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

defaultWebView.inputView.hidden = YES;

[self.view addSubview: self.defaultWebView];

[self.defaultWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
                                                            [NSString stringWithFormat:(NSString *)@"%@", @"http://www.google.com"]]]];

Thanks!

Community
  • 1
  • 1
Maor Zohar
  • 592
  • 5
  • 17

3 Answers3

2

There is no such thing as cancel a webView, what you need to do is remove the UIWebView from the parent view. If your UIWebView is a subview of self.view then you can provide a button named Close which behaves like this -

- (IBAction)closeWebView:(id)sender
{
    [self.webView removeFromSuperView];
    self.webView = nil;
    return;
}

This should remove the webview from your view.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • 1
    Thanks Srikar! For anyone who needs - this is how i did it: UIButton* hideWebViewBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; hideWebViewBtn.frame = CGRectMake(5, 5, 20, 30); [hideWebViewBtn addTarget:self action:@selector(hideWebViewBtn:) forControlEvents:UIControlEventTouchUpInside]; [defaultWebView addSubview:hideWebViewBtn]; [self.defaultWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:(NSString *)@"%@", @"http://www.oranim.ac.il/sites/heb/guide/lessons-administration/faq/Pages/default.aspx"]]]]; – Maor Zohar Nov 28 '11 at 19:12
  • 1
    And this is the method that release the webview: - (IBAction)hideWebViewBtn:(id)sender { [self.defaultWebView removeFromSuperview]; self.defaultWebView = nil; return; } – Maor Zohar Nov 28 '11 at 19:14
0

...way to make the user dismiss the WebView window...

[self.defaultWebView removeFromSuperview];
TigerCoding
  • 8,710
  • 10
  • 47
  • 72
0

look I will explain what happenes in the post you attached above and you will understand the technique,

the UIWebview is a component which views an web page, it may be html or other types, there is one way to hide your webview is to add an action in the html of the webview and ovveride the request in the code of your app, when you click on link or ahref or any action on UIwebview there is a delegate method which automatically runs before continuing with the request

  • (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

you can add a button or link on the html page and ovveride the request on this method for example

Thing to click

and in the delegate method

  • (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([[[request URL] absoluteString] isEqualToString:@"http://hideWebView/"]) { [self.webview setHidden:YES]; return NO; } return YES; }

here you ovveride the request http://hideWebView/ and in the delegate you searched for this request and then hiddes the web view or anything else you want to do

user784625
  • 1,928
  • 5
  • 24
  • 38