【问题标题】:How to make a class in one file work with UIWebViewController implemented in another file?如何使一个文件中的类与另一个文件中实现的 UIWebViewController 一起使用?
【发布时间】:2011-01-31 10:32:06
【问题描述】:

所以我在一个 .m 文件中实现了 UIWebView,在另一个文件中实现了 UITableView。当用户单击 UITableView 元素时,会出现 UIWebView。问题是我必须根据 UITableView 的行号设置 UIWebView 的内容(本地文本和图像)。我知道如何做到这一点,但这当然必须用 UITableView 实现,但它也需要 UIWebView。

仅导入 UIWebView 实现不起作用。

提前致谢!

【问题讨论】:

  • 你有要在tableview的webview中显示的url吗?
  • 没有。当用户点击 UITableView 行时,UIWebView 在导航控制器中显示为下一个视图。 UIWebView 包含带有图像的文本(内容取决于所选的 UITableView 行)。
  • 在将其推送到导航控制器之前,您是否尝试过将所需信息(行号、图像位置等)传递给 UIWebView
  • 使用委托方法从table view获取数据到webview
  • 即使我这样做,我也必须从我的 UITableView 实现文件中访问 UIWebView,不是吗?

标签: iphone objective-c uiwebview


【解决方案1】:

查看此链接以设置代表here

在 didSelectRowAtIndexpath 中

 NSString *name=@"content of table";
 myAppDelegate *appDelegate = (myAppDelegate *) [[UIApplication sharedApplication] delegate];
    [appDelegate setCurrentTitle:name]; 

PictureWebViewController *webview = [[PictureWebViewController alloc] initWithNibName:@"PictureWebViewController" bundle:nil];


[self.navigationController pushViewController:email animated:YES];

PictureWebViewController 是你的 webview 的类。

在 viewdidload 方法中的那个类中获取标题为

  myAppDelegate *appDelegate = (myAppDelegate *) [[UIApplication sharedApplication] delegate];
  NSString *name= [appDelegate getCurrentTitle];

使用该类中的名称在 webview 中显示内容。

一切顺利

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2012-12-30
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    相关资源
    最近更新 更多