IOS: display modal view on top of UIWebView

Can a modal view be displayed on top of a UIWebView? I have a UIViewController that loads a WebView. Then I want to click the Modal View Controller from above so that the modal view temporarily closes the WebView ...

WebView is working fine; here, how it loads into the view controller:

- (void)loadView {

    // Initialize webview and add as a subview to LandscapeController 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 try to load the Modal View controller from viewDidLoad, the modal view will not appear:

- (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 is something that needs to be done with the UIWebView delegate in order to get it to get a new modal view ... but cannot find any discussion or examples of this anywhere ... again, the goal is to get called a modal view that spans the top of WebView.

Thanks for any thoughts in advance!

+3
2

. presentModalViewController viewDidLoad viewDidAppear .

+4

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. , , , .

, !

0

Source: https://habr.com/ru/post/1781785/


All Articles