gpt4 book ai didi

ios - ListView 到uiwebview?

转载 作者:行者123 更新时间:2023-11-28 22:34:16 25 4
gpt4 key购买 nike

我可以在 ListView 中创建一个包含 5 个网站的列表,但我如何才能做到这一点..

单击列表中的一项后,它应该将我带到一个 uiwebview 以在应用程序中显示 URL,并带有返回 ListView 的后退按钮?

有这方面的示例或教程吗?

谢谢

尝试如下:(网站未出现在表格列表中 - 试图让它们出现并可点击以在应用程序内部打开)

名为“sites”的表格 View 已添加到我的应用程序的选项卡中。

tabcontroller.m

- (void)tableView:(UITableView *)sites didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch(indexPath.row)
{
case 0:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
break;

case 1:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.facebook.com"]];
break;

case 2:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
break;

case 3:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.yahoo.com"]];
break;

case 4:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.msn.com"]];
break;
}

}

tabcontroller.h

@interface TabController : UIViewController {

IBOutlet UITableView *sites;

}

最佳答案

使用 url 加载 webview

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];
  1. 创建 2 个 View Controller
  2. 第一个populate a tableview showing urls ,
  3. 第二个 VC 添加一个 UIWebview 并创建它的 IBoutlet
  4. On did select tableview method push second viewcontroller,通过网址
  5. 在第二个 View Controller 中使用上面的代码加载 webview带网址

关于ios - ListView 到uiwebview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com