views:

349

answers:

1

I have a root UIViewController which has a property called webView. WebView is a UIViewController with a XIB that contains a UIWebView. From my root view I modally (is there any other way?) load the webView ViewController and set its URL, always to the same page.

I discovered that if, after loading the webView, I used its default Web page to navigate to another Web page, and then closed the webView and returned to the root controller -- AND THEN reopened the webView, that the webView was not showing the default page but rather the page I navigated to, which means the webView ViewController never got destroyed and removed from memory. This strikes me as very bad.

So in the root ViewController, I added this code under viewWillAppear:animated --

if (self.webView != nil) {
    self.webView = nil)
}

Is that sufficient? Is there a better way?

A: 

I have a root UIViewController which has a property called webView. WebView is a UIViewController with a XIB that contains a UIWebView.

First, a style suggestion. Don't name your view controller classes FooView. Name them FooViewController. Because that's what they are. Controllers. Not Views.

From my root view I modally (is there any other way?) load the webView ViewController and set its URL, always to the same page.

You can bring a view on screen in any number of ways; presenting it as a model view controller is one way. Another would be to have a navigation controller and push it on the navigation stack. Another would be to use the animation primitives and swap an active view in and out.

If you're presenting the view controller modally, you should be using the delegate pattern, and having the "parent" view controller dismiss it modally when you want it go to away.

The answer I gave here:

http://stackoverflow.com/questions/2504478/pop-up-modal-with-uitableview-on-iphone/2504556#2504556

Is pretty close to the code you'll need, except you'll probably just want to have a simpler delegate protocol like:

@protocol FooViewControllerDelegate <NSObject>
- (void)fooViewControllerDidFinish:(FooViewController*)fooViewController;
@end
Shaggy Frog
You are right about naming viewcontrollers. Serves me right for borrowing code and then not implementing my naming scheme, under which it would be vcWeb. As for dismissing the modal vc, it calls this code: [self.parentViewController dismissModalViewControllerAnimated:NO]; I just had no idea that "dismissModal" didn't mean "destroy and remove from memory".
Scott Pendleton