iOS:显示UIWebView顶部的模态视图

是否有可能在UIWebView的顶部显示模态视图? 我有一个加载WebView的UIViewController。 然后,我想要在顶部推一个模态视图控制器,以便模态视图暂时覆盖WebView …

WebView工作正常; 这是它在View Controller中的加载方式:

- (void)loadView { // Initialize webview and add as a subview to LandscapeController's view myWebView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; myWebView.scalesPageToFit = YES; myWebView.autoresizesSubviews = YES; myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); myWebView.delegate = self; self.view = myWebView; } 

如果我尝试从viewDidLoad中加载模态视图控制器,则不会出现任何模态视图:

 - (void)viewDidLoad { [super viewDidLoad]; // Edit dcftable.html with updated figures NSMutableString *updated_html = [self _updateHTML:@"dcftable"]; // Load altered HTML file as an NSURL request [self.myWebView loadHTMLString:updated_html baseURL:nil]; // If user hasn't paid for dcftable, then invoke the covering modal view if (some_condition) { LandscapeCoverController *landscapeCoverController = [[[LandscapeCoverController alloc] init] autorelease ]; [self presentModalViewController:landscapeCoverController animated:YES]; } } 

我怀疑有一些事情需要UIWebView委托来完成,以获得新的模态视图…但无法find任何地方的任何讨论或例子…再次,目标是调用一个模态查看覆盖在WebView的顶部。

提前感谢您的任何想法!

我遇到了同样的问题。 将presentModalViewController调用从viewDidLoad移动到viewDidAppear的技巧。

我无法得到它在viewDidLoad工作,但我得到它的工作方式不同。 以下是我所做的:

 - (void)viewDidLoad { ... if (some_condition) { [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(showModal) userInfo:nil repeats:NO]; } } - (void)showModal { LandscapeCoverController *landscapeCoverController = [[[LandscapeCoverController alloc] init] autorelease ]; [self presentModalViewController:landscapeCoverController animated:YES]; } 

基本上,如果它没有在viewDidLoad被调用,它会起作用。 我希望我能解释一下为什么,我好奇自己,但至less应该解决你的问题。

希望这可以帮助!