简体   繁体   中英

UIWebView “decays” to UIView when added to navigation controller

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!

您可以尝试将UIWebView添加为控制器中主UIView的子视图。

I have same problem. If I set the view outlet of the ViewController to UIWebView it dont work. But the web view as a subview of a view works fine. Any particular reason, anybody knows? Apple documentation said only,

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM