Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

ios7 - 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.

question from:https://stackoverflow.com/questions/19125468/why-does-uinavigationbar-appearance-settranslucentno-crash-my-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...