views:

337

answers:

3

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
A: 

If you want to push a new view controller, you need to use -[UINavigationController pushViewController:animated:]. To display a web view, you'll need to create a new view controller with your web view in it, and then push that.

Ben Gottlieb
+2  A: 

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:[NSURL URLWithString:@"http://www.google.com"]];

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

  [self.navigationController pushViewController: webViewController animated:YES];
}
luvieere
A: 

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];
inornate