0

当用户选择行时,我想在另一个视图中打开 url。

4

3 回答 3

1

使用 UIWebVIew 在另一个视图中打开链接。

使用 tableView 的 didSelectRowAtIndexPath - 获取 tableview 的选定行。

在 didSelect 表视图委托上 - 导航到所需视图 - 使用 UIWebView 加载 URL

于 2013-01-24T11:10:13.967 回答
1

只需属性在您的另一个视图中合成该 url 并使用所选项目设置值..请参见下面的示例...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
yourNextViewController *objNextView = [[yourNextViewController alloc]initWithNibName:@"yourNextViewController" bundle:nil];

    objNextView.strURL = [yourArray objectAtIndex:indexPath.row];;
    [objNextView.strURL retain];
    [self.navigationController pushViewController:objNextView animated:YES];
    [objNextView release];
}

和属性,合成如下..

@interface yourNextViewController : UIViewController{
       NSString *strURL;
}
@property(nonatomic, retain)    NSString *strURL;
@end

@implementation yourNextViewController
@synthesize strURL;

使用后strURL

于 2013-01-24T11:19:24.620 回答
0

您需要使用didSelectRowAtIndexPath委托:

- (void)tableView:(UITableView *)tbView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"didSelectRowAtIndexPath %d",indexPath.row);
    // Either load your url here using the UIWebView or use the below code to open URL in safari.
    // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:hereURLYouWantToOpen]];
}

要在 UIWebView 中加载 URL,您可以使用以下代码:

UIWebView *webView = [[UIWebView alloc] initwithFrame:CGRectMake(your co-ordinate)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"your URL"]]];
于 2013-01-24T11:14:09.600 回答