控制和访问每个视图上的 webview

发布于 2024-10-09 10:12:32 字数 431 浏览 0 评论 0原文

基本上我在 SecondViewController 上有一个 webview,我希望 webview 在每个视图上都可见,就像选项卡栏一样,并且在每个视图上完全可控。

请注意,网络视图将位于带有在线幻灯片的网页上,因此我不能简单地在每个视图上重新加载

此外,在 SecondViewController 中我已经

- (void)webViewDidFinishLoad:(UIWebView *)MyWebView {

尝试过此操作

[self.view addSubview: SecondViewController.MyWebView ]

,但我不相信我正确使用它,因为我不知道如何声明SecondViewController

感谢

梅森

Basically i have a webview on SecondViewController, and i wish for the webview to be visible on every view like a tab bar and fully controllable on each view.

Please note the webview will be on a webpage with a online slideshow so i cannot simply reload on each view

Also in the SecondViewController i have

- (void)webViewDidFinishLoad:(UIWebView *)MyWebView {

i have tried this

[self.view addSubview: SecondViewController.MyWebView ]

but i don't believe i am using it correctly, for one i dunno how to declare SecondViewController

Thanks

Mason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤城病女 2024-10-16 10:12:33

不明白你到底想要什么,但你可以以模态方式呈现你的控制器:

MyWebViewController *wvc = [[MyWebViewController alloc]init];
wvc.myUrlIWantToOpenOnStart = @"http://www.mysampleurl.com";
[self presentModalViewController:wvc];
[wvc release];

didn't understood what you want exactly but you can present your controller modally:

MyWebViewController *wvc = [[MyWebViewController alloc]init];
wvc.myUrlIWantToOpenOnStart = @"http://www.mysampleurl.com";
[self presentModalViewController:wvc];
[wvc release];
椵侞 2024-10-16 10:12:32

Apple 表示当时只有一个 UIViewController,以避免方向问题和发送到视图控制器的其他通知出现问题。

因此,对于你的问题,我建议你有一个 UIViewController 来管理所有视图(作为视图控制器视图的子视图),并将 webview 作为子视图,但显示在其他子视图前面。

因此,当您需要更改视图时,只需在旧视图中执行removeFromSuperview,并在新视图中执行addSubview。

如果您绝对需要为您的视图使用不同的 UIViewController,您可以创建一个包含 UIWebView 成员和 isLoaded 布尔成员的单例类(单例类是 UIWebView 的委托,它检查内容是否已加载以设置 isLoaded 成员 如果

当您需要 UIWebView 时,只需使用单例类获取它,添加为子视图并检查内容是否已使用 isLoaded 成员加载。

内容尚未加载,请在 UIWebView 上执行 loadURL。

Apple says to have only one UIViewController at the time to avoid problems with orientation and other notifications sent to view controllers.

So for your problem, i suggest you to have a UIViewController that manages all your views (as subviews of the view controller's view) and have the webview as a subview also but showed in front of other subviews.

So when you need to change a view, you simply do a removeFromSuperview in your old view and a addSubview with your new view.

If you absolutely need to have different UIViewController for your views, you can create a singleton class that holds a UIWebView member and a isLoaded boolean member (the singleton class is the delegate of the UIWebView and it check if the content is loaded to set isLoaded member.

When you need the UIWebView, simply get it with the singleton class, add as subview and check if the content is already loaded with the isLoaded member.

If the content is not already loaded, do a loadURL on the UIWebView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文