views:

490

answers:

1

I'm working on a simple iPhone app prototype in which a selection from a UITableView takes the user to a UIWebView showing some content. My project is based on the "Navigation-based Application" template, so I have a UINavigationController managing flow. The problem is that my UIWebView seems to change into a generic UIView when I add it to the navigation stack, keeping me from sending it any URL-based content.

In Interface Builder, I added a UIViewController to the project, changed its class to DocViewController, and dropped a UIWebView into it. The DocViewController's view outlet is pointing to the UIWebView.

When an item in the UITableView is selected, I push a DocViewController on the stack:

NSLog(@"selected the row, creating the DocViewController");
DocViewController *docViewController = [[DocViewController alloc] init];
[self.navigationController pushViewController:docViewController animated:YES];
[docViewController release];

I'm checking the view outlet at viewDidLoad and viewWillAppear with NSLog statements:

NSLog(@"at viewDidLoad have view as %@", [self view]);
NSLog(@"at viewWillAppear have view as %@", [self view]);

So far so good... I think. When the app launches, DocViewController gets viewDidLoad, and I see this:

at viewDidLoad have view as <UIWebView: 0xd21db0; frame = (0 20; 320 460);...

When I select an item from the table view, though, viewDidLoad gets called again, followed by viewWillAppear, and I get these:

at viewDidLoad have view as <UIView: 0xd164e0; frame = (0 20; 320 460);...
at viewWillAppear have view as <UIView: 0xd164e0; frame = (0 0; 320 416);...

So the controller had a UIWebView when it pre-loaded, but when it's actually pushed on the stack, it has a UIView instead.

I have a feeling I'm misunderstanding something basic here, or have gone down the wrong path, or both. Can anyone suggest the proper pattern here, or point out where I've gone askew? Thanks very much in advance!

A: 

You could try adding the UIWebView as a subview of the main UIView in the controller.

chpwn