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

时间:2010-12-23 06:47:24

标签: ios uiwebview modalviewcontroller

是否可以在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顶部的模态视图。

提前感谢您的任何想法!

2 个答案:

答案 0 :(得分:4)

我遇到了同样的问题。将presentModalViewController来电从viewDidLoad移至viewDidAppear就可以了。

答案 1 :(得分:0)

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

希望这有帮助!