Modal View Controller首次显示空白,随后正常工作

我有一个模式的视图控制器,我试图在其中呈现一个Web视图。 这是第一次出现,它显示为空白。 当我把它closures并再次点击时,它显示正常。 我想这可能是加载的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]; 

直到第一次现在的调用导致控件加载和初始化,webView控件才会被第一次访问。 在第一次现在之前,webViewController.webView将是零,所以调用loadRequest将不会做任何事情。

您可以在presentModalViewController调用之后移动loadRequest调用。

但是不直接访问视图控制器视图中的控件,最好是在WebViewController中将urlstring声明为NSString属性(称为urlString),并在presentModalViewController调用之前将其设置为fileString(并且不要创buildNSURL,等等):

 webViewController.urlString = fileString; [self presentModalViewController:webViewController animated:YES]; 

最后,在WebViewControllerviewWillAppear:viewDidAppear: ,创buildNSURL(使用urlString),创buildNSURLRequest并调用loadRequest。