我会说这是失败的if语句if ([[ver objectAtIndex:0] intValue] >= 7)
。我将取代整个if statement
有:
if([[[UIDevice currentDevice] systemVersion] intValue] >= 7) {
// Do the below if you want to set the bar tint color for every UINavigationBar
// [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
// [[UINavigationBar appearance] setTranslucent:NO];
[[[self navigationController] navigationBar] setBarTintColor:[UIColor redColor]];
[[[self navigationController] navigationBar] setTranslucent:NO];
} else {
// Do the below if you want to set the bar tint color for every UINavigationBar
// [[UINavigationBar appearance] setTintColor:[UIColor redColor]];
[[[self navigationController] navigationBar] setTintColor:[UIColor redColor]];
}
[[UIDevice currentDevice] systemVersion];
将返回NSString *
,可以是任何东西,从7
到7.0.1
。这样做floatValue
将返回至少7.0
,因为它会追加0
在结束时,如果它只是返回7
,所以我们希望它永远只给我们的7
初始系统版本,所以我们需要做intValue
就结束,所以它看起来像[[[UIDevice currentDevice] systemVersion] intValue];
忘记componentSeperatedByString:
方法根本不需要,它会导致更多的问题,然后你想要的。
你也可以做这样的if statement
if (floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_7_0) {
// Everything above and including iOS 7.0
} else {
// Everything below iOS 7.0
}
在您添加代码的委托文件或?? – Yohan
确保你的'self.navigationController'不应该是零。 –
并尝试'if([[[UIDevice currentDevice] systemVersion] floatValue]> = 7)'而不是使用数组。 –