Я использую 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 и поставлю два идентификатора в 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;
}
}