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

标签 ios uiwebview modalviewcontroller

是否可以在 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/

相关文章:

objective-c - 更改模态 UIActivityViewController 的外观

iphone - xcode可以将iphone sdk安装到xcode开发工具吗

ios - UIWebView使用iframe无法自动播放而不自动播放

ios - NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9802)错误

animation - 横向iPad上带有键盘的模态视图 Controller 在关闭时更改位置

objective-c - 调用当前 Modal ViewController 导致 “EXC_BAD_ACCESS”

ios - 在 ios 9.1 中运行我的旧项目时显示此错误。iPhoneOS9.1.sdk/usr/lib/libsqlite3.dylib (没有这样的文件或目录)

ios - 从自定义对象数组中获取属性的逗号分隔字符串

ios - 为什么当我清除数组时内存没有被释放?

html - 在不破坏链接的情况下将本地文件注入(inject) UIWebView