如何解决UInavigation控制器不起作用
| 我正在制作应用程序,就像设备每次更改其方向模式时都会更改其视图一样。 首先,当视图为纵向时,它显示完美的SearchViewController,然后当我旋转为横向时,将其推入横向的新视图MapView中。现在,当我再次将视图更改为纵向时,地图将旋转为纵向...但应该是做搜索视图控制器...,当我点击详细信息披露按钮时,还有一件事情应该回到搜索视图控制器...我认为导航控制器在地图视图中不起作用。 这是我的searchViewController的代码部分- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| inte rfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else {
MapView *mapView = [[MapView alloc] initWithNibName:@\"MapView\" bundle:nil];
mapView.title = @\"Map\";
[self.navigationController pushViewController:mapView animated:YES];
return YES;
}
return YES;
}
这是我的MapView代码
- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| UIInterfaceOrientationLandscapeLeft);
if(interfaceOrientation == UIInterfaceOrientationPortrait|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@\"hi Potrait\");
[self.navigationController popViewControllerAnimated:NO];
return YES;
}
else {
}
return YES;
}
解决方法
shouldAutorotateToInterfaceOrientation:
是实施任何类型导航的不正确位置。您应该改用didRotateFromInterfaceOrientation:
。检查当前的interfaceOrientation
,必要时推动或弹出。
在searchViewController
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ) {
MapView *mapView = [[MapView alloc] initWithNibName:@\"MapView\" bundle:nil];
mapView.title = @\"Map\";
[self.navigationController pushViewController:mapView animated:YES];
}
}
在MapView
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ( UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ) {
[self.navigationController popViewControllerAnimated:NO];
}
}
然后将您的shouldAutorotateToInterfaceOrientation:
更改为
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。