landscapeCoverController

landscapeCoverController

我正在尝试从Modal View Controller(第二个)加载Modal View Controller(第一个)。虽然听起来很复杂,但事实并非如此。

第一个控制器实际上是一个UIWebView,它是在.m文件的loadView方法中初始化的:

- (void)loadView {

    // Initialize webview and add as a subview to LandscapeController's view
    myWebView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
    //CGRect forceframe = CGRectMake(0, 0, 480, 320);
    //myWebView = [[[UIWebView alloc] initWithFrame:forceframe] autorelease];
    myWebView.scalesPageToFit = YES;
    myWebView.autoresizesSubviews = YES;
    myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    myWebView.delegate = self;
    self.view = myWebView;
}


然后在viewDidLoad中:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Load HTML file as an NSURL request
    [self.myWebView loadHTMLString:updated_html baseURL:nil];

    // Invoke the covering modal view on condition
    if (some_condition) {
        landscapeCoverController = [[UIViewController alloc] initWithNibName:@"LandscapeCoverController" bundle:[NSBundle mainBundle]];

        [self presentModalViewController:landscapeCoverController animated:YES];
        [landscapeCoverController release];
    }


预期的第二模式视图控制器(landscapeCoverController)使用我在IB中设置的NIB进行了初始化。

我的预期目标是使用“ LandscapeCoverController”视图有条件地覆盖UIWebView,该视图将具有一些按钮和交互性,这将导致第二个模式视图被取消。

为什么我的landscapeCoverController没有加载?任何想法,不胜感激!

另外...第一个模态视图控制器(LandscapeViewController).h看起来像:

@class LandscapeCoverController;

@interface LandscapeViewController : UIViewController <UIWebViewDelegate> {
    UIWebView *myWebView;

    LandscapeViewController *landscapeCoverController;
}

@property (nonatomic, retain) UIWebView *myWebView;

@property (nonatomic, retain) LandscapeViewController *landscapeCoverController; // Modal view controller


和...第二模态视图控制器(landscapeCoverController)viewDidLoad不执行任何操作:

// NIB initialized in LandscapeViewController.m viewDidLoad:
- (void)viewDidLoad {
    [super viewDidLoad];

}


我认为

landscapeCoverController = [[UIViewController alloc] initWithNibName:@"LandscapeCoverController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:landscapeCoverController animated:YES];
[landscapeCoverController release];


语句应处理控制器的初始化和加载...

最佳答案

您将landscapeCoverController声明为LandscapeViewController的实例,并将其分配为UIViewController。这很可能是您的问题(可能是第一个问题,因为您没有调用特定于LandscapeViewController的任何方法)。另外,由于landscapeCoverController是一个实例变量,因此您实际上不需要在presentModalViewController之后释放它。尝试选择更多不同的类名。它将使您免于将来像这样的混乱。

关于iphone - 模态UIViewController没有出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4420531/

10-14 20:18