iPhone SDK:UIWebView [英] iPhone SDK: UIWebView

查看:37
本文介绍了iPhone SDK:UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用UIWebView来显示其帮助文件的应用程序.该webView位于其自己的视图DocViewController中,当它称为

I'm working on an app that uses a UIWebView to display its help files. The webView lives in it's own view, DocViewController...when its called the

- (void)viewDidLoad {

方法使用

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:   [[NSBundle mainBundle] pathForResource:docPage ofType:@"html"]isDirectory:NO]]];

加载正确的文档页面.但是,一旦加载了第一页,当docPage更改并且切换了视图时,视图将变为静态并且不会加载新页面.有没有一种方法可以清除webView,以便在请求时加载新页面?

to load the proper doc page. However, once the first page is loaded, the view becomes static and new pages aren't loaded when the docPage changes and the view is toggled. Is there a way to clear the webView so new pages load when requested?


第一个答案使我感到困惑.如下面的例程所示.只是它一次只能运行一次.第一次加载视图后,再次打开该视图并且请求的html页面不同时,它不会更改.该视图始终显示请求的第一个html页面,并且不会加载新请求.


The first answer is confusing to me. As is the routine below works. It's just that it only works once. After the view is loaded the first time it does not change when this view is toggled on again and the requested html page is different. The view always displays the first html page requested and will not load new requests.

 - (void)viewDidLoad {

     docPage = [NSString stringWithFormat: @"%d", hexpage];

     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[NSBundle mainBundle] pathForResource:docPage ofType:@"html"]isDirectory:NO]]];

 }

推荐答案

viewDidLoad 仅被调用一次,除非该视图被释放并需要重新加载.通常仅在视图控制器收到内存不足警告时才会发生这种情况.尝试将代码放在 viewWillAppear:中,而不是 viewDidLoad ,每次在屏幕上显示视图时都会调用该代码.

viewDidLoad is only called once, unless the view is released and needs to be reloaded. This occurs usually only when the view controller receives a low memory warning. Instead of viewDidLoad, try putting that code in viewWillAppear:, which gets called every time the view will show on the screen.

这篇关于iPhone SDK:UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆