Objective-c – iPhone SDK: UIWebView

iphoneobjective cuiwebview

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 {

method uses

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

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?

Edit:
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]]];

 }

Best Answer

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.

Related Topic