开发者

iOS: display modal view over the top of a UIWebView

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开发者_如何学Python any thoughts in advance!


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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜