模态视图控制器第一次显示空白,随后正常工作
我有一个模态视图控制器,我试图在其中呈现一个网络视图。第一次出现时,它显示为空白。然而,当我关闭它并再次单击它时,它显示正常。我认为这可能是 webView 加载的问题,但我尝试仅在 webView 完成加载时显示它,但那时它永远不会被调用。
NSURL* newURL = [[NSURL alloc] initFileURLWithPath: fileString];
NSURLRequest *newURLRequest = [[NSURLRequest alloc] initWithURL: newURL];
[webViewController.webView loadRequest: newURLRequest];
[newURL release];
[newURLRequest release];
webViewController.modalPresentationStyle=UIModalPresentationPageSheet;
[self presentModalViewController:webViewController animated:YES];
I have a modal view controller that I am trying to present a web view in it. Tthe first time it appears, it shows up as blank. When I close it out and click it again, however, it displays fine. I'm thinking it may be an issue with the loading of the webView, but I've tried displaying it only when the webView finishes loading, but it never gets called then.
NSURL* newURL = [[NSURL alloc] initFileURLWithPath: fileString];
NSURLRequest *newURLRequest = [[NSURLRequest alloc] initWithURL: newURL];
[webViewController.webView loadRequest: newURLRequest];
[newURL release];
[newURLRequest release];
webViewController.modalPresentationStyle=UIModalPresentationPageSheet;
[self presentModalViewController:webViewController animated:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一次出现的调用导致控件被加载和初始化之前,第一次无法访问 webView 控件。在第一个呈现之前,webViewController.webView 将为 nil,因此对其调用 loadRequest 将不会执行任何操作。
您可以将 loadRequest 调用移到presentModalViewController 调用之后。
但是,与其直接访问视图控制器视图中的控件,不如在 WebViewController 中将 url 字符串声明为 NSString 属性(称为 urlString),并在调用 PresentModalViewController 之前将其设置为 fileString(并且不要创建 NSURL,等):
最后,在 WebViewController 中,在
viewWillAppear:
或viewDidAppear:
中,创建 NSURL(使用 urlString ),创建 NSURLRequest,并调用 loadRequest。The webView control won't be accessible the first time until the first present call causes controls to be loaded and initialized. Before the first present, webViewController.webView will be nil and so calling loadRequest on it will do nothing.
You could move the loadRequest call after the presentModalViewController call.
But instead of accessing controls in view controller's views directly, it'd be better to declare the url string as a NSString property (called say urlString) in WebViewController and set it to fileString before the presentModalViewController call (and don't create the NSURL, etc there):
Finally, in WebViewController, in
viewWillAppear:
orviewDidAppear:
, create the NSURL (using urlString), create the NSURLRequest, and call loadRequest.