You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode9.2打开Xcode7.3项目报错:No known instance method for selector setNeedsStatusBarAppearanceUpdate

Fixing "No known instance method for selector 'setNeedsStatusBarAppearanceUpdate'" in Xcode 9.2

Hey there, let's work through this error you're hitting after moving your Xcode 7.3 project to Xcode 9.2! The issue boils down to a shift in how iOS handles status bar appearance updates in newer SDK versions.

Why This Error Pops Up

Back in older iOS versions (like iOS 7, which your code checks for), sending setNeedsStatusBarAppearanceUpdate directly to a UIWindow might have worked as a hack. But starting from later iOS releases (and enforced by the iOS 11 SDK used in Xcode 9.2), this method is exclusively part of UIViewController — UIWindow no longer implements this selector, which is why the compiler throws that error.

The Solution

Instead of calling the method on the window, you need to target your app's root view controller, since that's the component Apple designates to manage status bar appearance. Here's how to update your code:

- (void)setStatusBarHidden:(BOOL)statusBarHidden {
    _statusBarHidden = statusBarHidden;
    if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) {
        // Grab the key window's root view controller (more reliable than firstObject)
        UIViewController *rootVC = [[[UIApplication sharedApplication] keyWindow] rootViewController];
        // Call the update method on the view controller instead of the window
        [rootVC setNeedsStatusBarAppearanceUpdate];
    }
}

Quick Extra Tip

Make sure your root view controller (or any view controller responsible for status bar state) properly implements methods like prefersStatusBarHidden to reflect the _statusBarHidden value you're setting. This ensures the update actually triggers the correct status bar change.

内容的提问来源于stack exchange,提问作者Vinu Jacob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:08:40