ios - 警告 : Attempt to present ViewController on TabBarController whose view is not in the window hierarchy

标签 ios objective-c xcode5 segue

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

好的,我有一个 UIViewController(它的父 View 是一个 UINavigationController,然后是一个 UITabBarController)被迫处于纵向模式.这家伙有能力以模态方式呈现另一个 UIViewController,当用户旋转设备时,它被迫保持横向模式。我决定使用手动转场来展示最后一个人。 这是演示文稿的代码:

- (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];
}

为了返回到第一个 View Controller ,我使用了这些代码

- (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];
    }
}

当我旋转设备时,第二个 View Controller 会生成警告

为什么??

谢谢

最佳答案

Warning: Attempt to present ViewController on TabBarController which view is not in the window hierarchy 。这个警告​​是因为当你push: or present: viewController 中的 viewController 不在 View 中。意思是您的第一个 View Controller 尚未加载或完全显示,但您正在展示或推送另一个 View Controller 。

关于ios - 警告 : Attempt to present ViewController on TabBarController whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25055741/

相关文章:

android - 使用 PhoneGap + HTML5 和嵌入的 Flash 电影

ios - 是否可以平铺纹理 SKShapeNode

ios - APNS打开应用程序的某个部分

ios - XCode 5.x + Maverick 在文件操作时崩溃

ios - iCloud:NSUbiquitousKeyValueStore 问题

ios - 允许编辑 UIImagePickerViewController 无法选择 2 个不同的图像

ios - AF网络 2 : Limit max number of concurrent Download Tasks

iphone - 可以使用 popViewController Animated 传递数据吗?

objective-c - 在 Cocoa 应用程序中编辑 NSBezierPath

ios - 在 Xcode 5 项目中使用 Core Plot 2