我正在尝试从模态视图控制器(第 2 个)加载模态视图控制器(第 1 个)。虽然听起来很复杂,但可能并非如此。
第一个控制器实际上是一个 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];
语句应该处理控制器的初始化和加载...