警告:尝试在其视图不在窗口层次结构中的TabBarController上显示ViewController

问题描述 投票:0回答:3

我知道这是一个常见问题,但似乎找不到适合我需求的正确解决方案。

确定,我有一个UIViewController(其父视图是UINavigationController,然后是UITabBarController)必须处于纵向模式。这个人可以模态显示另一个,当用户旋转设备时,该被强制停留在横向模式。我决定使用手动搜索来介绍最后一个家伙。这是演示文稿的代码:- (void)viewDidAppear:(BOOL)animated { [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)orientationChanged:(NSNotification *)notification { // Respond to changes in device orientation if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { [self performSegueWithIdentifier:@"gallerySegue" sender:self]; } } -(void) viewDidDisappear { // Request to stop receiving accelerometer events and turn off accelerometer [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; }

为了返回第一个视图控制器,我使用了这些代码段

- (void)viewDidAppear:(BOOL)animated { [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(returnBack:) name:UIDeviceOrientationDidChangeNotification object:nil]; } -(void) viewDidDisappear { // Request to stop receiving accelerometer events and turn off accelerometer [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; } - (void)returnBack:(NSNotification *)notification { // Respond to changes in device orientation if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { [self dismissViewControllerAnimated:NO completion:nil]; } }

警告

是由第二个视图控制器在旋转设备时生成的。为什么?

谢谢

我知道这是一个常见问题,但似乎找不到适合我需求的正确解决方案。好的,我有一个UIViewController(该父视图是一个UINavigationController,然后是一个...

ios objective-c xcode5 segue
3个回答
1
投票
Warning: Attempt to present ViewController on TabBarController whose view is not in the window hierarchy。此警告是因为当您从视图控制器中不在视图中的push:present:出现viewController时。意味着您的第一个视图控制器尚未加载或未完全显示,但是您正在从该ViewController中呈现或推送另一个。

0
投票
已解决!

0
投票
我是一位快速用户,但我认为在这里值得一提:
© www.soinside.com 2019 - 2024. All rights reserved.