我正在使用iOS5和故事板。我有兩個不同的標識符視圖。 我想在更改設備的方向時更改視圖。 這是我的代碼:iOS - 用設備方向更改視圖
- (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;
}
}
好的,如果我添加兩個uiview,並且我將這兩個id分配給這些時,我旋轉設備的應用程序崩潰。 看看編輯。 – Kerberos
崩潰說什麼? – Peres
無法識別的選擇發送到實例0x745bbe0 – Kerberos