开发者

Control and access webview on each view

开发者 https://www.devze.com 2023-02-02 00:06 出处:网络
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.

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 *开发者_Python百科)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


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.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消