我正在使用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