是否可以在 UIWebView 的顶部显示模态视图?我有一个加载 WebView 的 UIViewController。然后我想将模态视图 Controller 推到顶部,以便模态视图暂时覆盖 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 中加载模态视图 Controller ,则不会出现模态视图:
- (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 委托(delegate)做一些事情才能让它接收新的模态视图......但是在任何地方都找不到任何讨论或例子......再次强调,目标是调用覆盖 WebView 顶部的模态视图。
提前感谢您的任何想法!
最佳答案
我遇到了同样的问题。将 presentModalViewController
调用从 viewDidLoad
移动到 viewDidAppear
就可以了。
关于iOS:在 UIWebView 的顶部显示模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4516483/