开发者

How to push WebView in NavigationController

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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜