我是 iOS 和 Objective-C 的新手。
在我深入研究之前,我想知道我是否可以创建一个每个链接到特定 URL 的项目的 TableView ,这样当我点击一个项目时它会切换到一个 WebView该特定 URL。
只需要知道这是否可以使用 tableview 或者我是否需要使用其他东西。谢谢。
最佳答案
也许一些代码可以帮助....
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGectMake(0,0,320,480)];
URLViewController *controller = [[URLViewController alloc] init];
controller.view = webView;
controller.urlToShow = @"http://google.com";
[self.navigationController pushViewController:controller animated:YES];
[webView release];
[controller release];
}
URLViewController 将成为 UIViewController 的子类。假设它有一个名为 urlToShow 的属性,然后您可以在 viewDidLoad 方法中的 Web View 中显示 URL
-(void)viewDidLoad
{
NSString *urlAddress = urlToShow;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
UIWebView* webView = (UIWebView*)self.view;
[webView loadRequest:requestObj];
}
关于iOS:我可以链接 UITableView 的项目来调用 UIWebView 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7878216/