iOS:在 UIWebView 顶部显示模式视图

发布于 2024-10-08 21:13:36 字数 1408 浏览 3 评论 0原文

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

WebView 工作正常;这是它在视图控制器中的加载方式:

- (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 委托执行一些操作才能使其接收新的模态视图...但在任何地方都找不到任何讨论或示例...同样,目标是调用覆盖 WebView 顶部的模态视图。

感谢您提前提出任何想法!

Is it possible to display a modal view over the top of a UIWebView? I have a UIViewController that loads a WebView. I then want to push a Modal View Controller over the top so that a modal view covers up the WebView temporarily...

The WebView is working fine; here's how it's loaded in the 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; 
}

If I attempt to load a Modal View controller from within viewDidLoad, however, no modal view appears:

- (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];    
    }   


}

I suspect that there's something that needs to be done with the UIWebView delegate to get it to receive the new modal view...but can't find any discussion or examples of this anywhere...again, the objective is to invoke a modal view that covers over the top of the WebView.

Thanks for any thoughts in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝有风,海豚有海 2024-10-15 21:13:36

我遇到了同样的问题。将 presentModalViewController 调用从 viewDidLoad 移动到 viewDidAppear 就成功了。

I ran into this same problem. Moving the presentModalViewController call from viewDidLoad to viewDidAppear did the trick.

把昨日还给我 2024-10-15 21:13:36

我也无法让它在 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 中调用它,它就会起作用。我希望我能解释为什么,我自己很好奇,但这至少应该解决你的问题。

希望这有帮助!

I couldn't get it to work in viewDidLoad either, but I got it to work in a different method. Here's what I did:

- (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];    
}

Basically, it works if it's not being called in viewDidLoad. I wish I could explain why, I'm curious myself, but this should at least fix your problem.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文