【发布时间】:2009-08-30 09:34:18
【问题描述】:
我是 iPhone 开发的新手,有一个问题,可能最终有助于理解这个概念。
基本上,我有 UIViewController 可以加载一个包含一堆东西的视图。现在我想当用户点击一个按钮时,加载一个不同的视图,这恰好是一个 webView。现在,我希望 weview 根据在原始视图中按下的按钮加载不同的 url。
我该怎么做呢?基本上在我的脑海中,我认为我可以在按下按钮时加载和交换视图,如下所示:
在
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedLink = [valuesForSection objectAtIndex:row];
NSString *urlAddress = @"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
[self.view removeFromSuperview];
[self.view insertSubview:webView atIndex:0];
}
这是正确的做法吗?或者我该怎么做?
【问题讨论】:
标签: iphone iphone-sdk-3.0 uiwebview