简体   繁体   English

当添加到导航控制器时,UIWebView会“衰减”到UIView

[英]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. 我正在研究一个简单的iPhone应用程序原型,其中从UITableView中进行选择将用户带到显示一些内容的UIWebView。 My project is based on the "Navigation-based Application" template, so I have a UINavigationController managing flow. 我的项目基于“基于导航的应用程序”模板,因此我有一个UINavigationController管理流程。 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. 问题是,当我将其添加到导航堆栈时,我的UIWebView似乎变成了通用的UIView,使我无法向其发送任何基于URL的内容。

In Interface Builder, I added a UIViewController to the project, changed its class to DocViewController, and dropped a UIWebView into it. 在Interface Builder中,我向项目添加了UIViewController,将其类更改为DocViewController,然后将UIWebView放入其中。 The DocViewController's view outlet is pointing to the UIWebView. DocViewController的视图出口指向UIWebView。

When an item in the UITableView is selected, I push a DocViewController on the stack: 当选择UITableView中的项目时,我将DocViewController推入堆栈:

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语句检查viewDidLoad和viewWillAppear的视图出口:

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: 应用启动时,DocViewController会获取viewDidLoad,我看到了这一点:

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: 但是,当我从表视图中选择一个项目时,再次调用viewDidLoad,然后再调用viewWillAppear,得到以下这些:

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. 因此,控制器在预加载时具有UIWebView,但实际上将其推入堆栈时,却具有UIView。

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. 如果我将ViewController的视图出口设置为UIWebView,它将无法正常工作。 But the web view as a subview of a view works fine. 但是将Web视图作为视图的子视图可以正常工作。 Any particular reason, anybody knows? 任何特定的原因,有人知道吗? Apple documentation said only, 苹果文件只说

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. 重要说明:您不应在UIScrollView对象中嵌入UIWebView或UITableView对象。 If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. 如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混合在一起并且处理不当。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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