How to push WebView in NavigationController

10,188

Solution 1

Code above is not working, also has some leak. -

Here's the modified version.

UIViewController *webViewController = [[[UIViewController alloc] 
    init] autorelease];

UIWebView *uiWebView = [[[UIWebView alloc] 
    initWithFrame: CGRectMake(0,0,320,480)] autorelease];
[uiWebView loadRequest:[NSURLRequest 
    requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

[webViewController.view addSubview: uiWebView];

[self.navigationController 
    pushViewController:webViewController animated:YES];

Solution 2

Here you go:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  UIViewController *webViewController = [[UIViewController alloc] init];

  UIWebView *uiWebView = [[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)];
  [uiWebView loadRequest:[NSURLRequest requestWithURL:
                             [NSURL URLWithString: @"http://www.google.com"]]];

  [webViewController.view addSubview: uiWebView];
  [uiWebView release];

  [self.navigationController pushViewController: webViewController animated:YES];
}
Share:
10,188
marcy
Author by

marcy

Updated on June 04, 2022

Comments

  • marcy
    marcy almost 2 years

    I want to display web view when table cell is selected

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      [uiWebView loadRequest:[NSURL URLWithString:@"http://www.google.com"]];
    
      [self.navigationController pushNavigationItem:uiWebView animated:YES];
    }
    

    log

    -[UINavigationController pushNavigationItem:animated:]: unrecognized selector sent to instance