iOS AppDelegate 添加supportedInterfaceOrientationsForWindow

标签 ios objective-c xcode appdelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
    if (self.fullScreenVideoIsPlaying == YES)
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        if(self.window.rootViewController)
        {
            UIViewController *presentedViewController = [[(UINavigationController  *)self.window.rootViewController viewControllers] lastObject];
            orientations = [presentedViewController supportedInterfaceOrientations];
        }
        return orientations;
    }
}

我尝试仅更改一页屏幕方向,并在启动程序时添加此功能,程序无法启动,给出此错误初始屏幕 错误:

2015-02-06 00:40:24.264 AppName[5002:1189245] -[SplashScreen viewControllers]: unrecognized selector sent to instance 0x14d510010
2015-02-06 00:40:24.266 AppName[5002:1189245] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SplashScreen viewControllers]: unrecognized selector sent to instance 0x14d510010'
*** First throw call stack:
(0x18269659c 0x192da00e4 0x18269d664 0x18269a418 0x18259eb6c 0x100098614 0x186ebc594 0x186ebc210 0x186ec548c 0x186ec4ee0 0x186ebc154 0x1870d45f0 0x1870d362c 0x1870d1dec 0x18a90d62c 0x18264ea28 0x18264db30 0x18264bd30 0x1825790a4 0x186eb33c8 0x186eae3c0 0x100102560 0x19340ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

有什么想法吗??我该如何解决这个问题?

最佳答案

也许您想将 viewControllers 更改为 childViewControllers

编辑 1:抱歉,我现在才注意到您认为您的 rootViewControllerUINavigationViewController

这显然不是您从错误消息中看到的那样。它属于 SplashScreen

编辑 2:我建议您执行以下操作并从那里开始

if(self.window.rootViewController && [self.window.rootViewController isKindOfClass:[UINavigationViewController class]])
{
        UIViewController *presentedViewController = [[(UINavigationController  *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presentedViewController supportedInterfaceOrientations];
}

return orientations;

关于iOS AppDelegate 添加supportedInterfaceOrientationsForWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355482/

相关文章:

ios - SDImageCache - 4.0 迁移后无法识别的选择器错误

ios - CFReadStreamRead 在 iOS 7 下永远阻塞

ios - 我应该在哪里放置我的全局宏?

ios - IOS中minimumFontSize和minimumScaleFactor的区别

ios - UICollectionView 崩溃

iphone - 在 View 中添加多个标签

java - 在 Android 和 Java 上复制 Swift 完成处理程序

ios - 从字典访问 FlutterStandardTypedData 时出现 "[__NSArrayI data]: unrecognized selector"

iphone - 如何创建导航 Controller 以将主视图 Controller 连接到 2 个自定义 View Controller

ios - 代码 8 : Preparing Archive takes forever