2009-11-15 14 views
2

我要顯示Web視圖當表格單元格選定如何推動的WebView在NavigationController

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

    [self.navigationController pushNavigationItem:uiWebView animated:YES]; 
} 

日誌

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

回答

0

如果你想推一個新的視圖控制器,你需要使用 - [UINavigationController pushViewController:animated:]。要顯示Web視圖,您需要創建一個新的視圖控制器,其中包含Web視圖,然後再推送它。

4

在這裏你去:

- (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]; 
} 
+1

它需要是: [UIWebView中的loadRequest:的NSURLRequest requestWithURL:[NSURL URLWithString:(的NSString *)@ 「http://www.google.com」]]]; – Sebastian

14

上面的代碼不工作,也有一些泄漏。 -

這裏是修改後的版本。

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]; 
在最新的SDK
相關問題