3

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

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

4

2 回答 2

4

我遇到了同样的问题。将presentModalViewController呼叫从viewDidLoad移到就可以viewDidAppear了。

于 2010-12-23T19:43:10.647 回答
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。我希望我能解释为什么,我自己很好奇,但这至少应该解决你的问题。

希望这可以帮助!

于 2010-12-23T08:46:50.250 回答