Search code examples
uinavigationbarios7

Why does [[UINavigationBar appearance] setTranslucent:NO] crash my app?


Same question as this, but that question was shunned (because of NDA at the time) and is no longer active.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'

I'm setting this in viewDidLoad of my initial view controller. setTranslucent comes up on autocomplete, and does not complain until crashing and talking about swizzles and things.

Any info on this would be great, I'm still having a very rough time getting a consistent status bar appearance across my app.


Solution

  • It seems that the translucent property just can't be set using UIAppearance. I don't know exactly why, but I guess some properties just aren't supported. However, I solved this by creating a custom UIViewController and making all other viewControllers in my app a subclass of that custom viewController. That way, I can set global properties (such as translucent in your case) that will be inherited by all other viewControllers in my app. I know that's kind of a big change, but I hope it helps.

    **** EDIT ****

    As of iOS 8, translucency can be set with UIAppearance:

    Objective C

    if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
    
        [[UINavigationBar appearance] setTranslucent:YES];
    }
    

    Swift

    if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 {
    
        UINavigationBar.appearance().translucent = true
    }