Iphone 在UITableView中创建指向URL的行
我有一个表,其中列出了我希望使表中的每一行指向分配给每个项目的URL的项目。选择单元格时,将调用-tableview:didselectRowatinedexpath:delegate方法。在此基础上,假设您拥有每行的url,下面的代码将在Safari中打开urlIphone 在UITableView中创建指向URL的行,iphone,objective-c,Iphone,Objective C,我有一个表,其中列出了我希望使表中的每一行指向分配给每个项目的URL的项目。选择单元格时,将调用-tableview:didselectRowatinedexpath:delegate方法。在此基础上,假设您拥有每行的url,下面的代码将在Safari中打开url NSURL *url = /* Assume this exists */; if( [[UIApplication sharedApplication] canOpenURL:url] ) { [[UIApplication
NSURL *url = /* Assume this exists */;
if( [[UIApplication sharedApplication] canOpenURL:url] )
{
[[UIApplication sharedApplication] openURL: url];
}
选择单元格时,将调用-tableview:didSelectRowAtIndexPath:delegate方法。在此基础上,假设您拥有每行的url,下面的代码将在Safari中打开url
NSURL *url = /* Assume this exists */;
if( [[UIApplication sharedApplication] canOpenURL:url] )
{
[[UIApplication sharedApplication] openURL: url];
}
如果不想离开应用程序,可以在UIWebView中打开url
UIWebView * wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
[self.view addSubview:wv]; // or push onto Navigation Stack
// if adding wv as subview, also need to add a back button to self.view to dismiss webview.
[wv loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString: myURLForSelectedRow]]];
[wv autorelease];
如果不想离开应用程序,可以在UIWebView中打开url
UIWebView * wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
[self.view addSubview:wv]; // or push onto Navigation Stack
// if adding wv as subview, also need to add a back button to self.view to dismiss webview.
[wv loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString: myURLForSelectedRow]]];
[wv autorelease];
在tableview委托函数didSelectRowAtIndexPath中,可以使用此代码在Safari应用程序中打开url
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url];
}
在tableview委托函数didSelectRowAtIndexPath中,可以使用此代码在Safari应用程序中打开url
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url];
}
是的,行中的每个条目都指向不同的URL是的,行中的每个条目都指向不同的URL