我很难获得一个非常简单的视图来显示。此视图有一个自定义视图控制器,由切换视图控制器管理。XIB 上有一个 UIViewController 组件,其 Image 属性集。视图控制器如下:
说明ViewController.h
#import <UIKit/UIKit.h>
@interface InstructionsViewController : UIViewController {
}
@end
InstructionsViewController.m
#import "InstructionsViewController.h"
@implementation InstructionsViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
我还将 XIB 的 File's Owner 的类属性设置为 InstructionsViewController,将 Ctrl+Dragged File's Owner 设置为 View 图标并从弹出菜单中选择 View。
显示视图的代码是:
- (void) showInstructions
{
//Lazy load the instruction view.
if (self.instructionsViewController == nil)
{
InstructionsViewController *viewController = [[InstructionsViewController alloc]
initWithNibName:@"InstructionsView"
bundle:nil];
self.instructionsViewController = viewController;
[viewController release];
}
[self.view insertSubview:viewController.view atIndex:0];
}
我的视图控制器在切换不同视图时为它们设置动画,加载和显示其他三个视图没有问题。它只是不喜欢这个。
我确定我错过了一些简单的东西,但是对于我的生活,由于某种原因我无法让它工作。有没有人有任何指示?
谢谢,
史蒂夫