我正在使用 iOS5 和情节提要。我有两个具有两个不同标识符的视图。我想在更改设备方向时更改视图。这是我的代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"];
}
else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Portrait"];
}
return YES;
}
但应用程序崩溃。哪个是问题?
编辑:如果我添加两个 uiview 并在旋转设备时将两个 id 放入 uiview 它会崩溃。这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (void) orientationChanged:(id)object
{
portraitView = [self.storyboard instantiateViewControllerWithIdentifier:@"TermoregolatoreTop"];
landscapeView = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"];
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portraitView;
}
else
{
self.view = self.landscapeView;
}
}