6

在我的 AppDelegate 中,我使用外观代理来制作自定义 UI:

//Setup custom appearances
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

这将在 iOS4 中崩溃。如何检查此功能在他们运行的 iOS 版本上是否可用,从而避免崩溃?

4

2 回答 2

19

不要检查操作系统,检查功能是否存在。

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {}

于 2011-11-04T20:13:24.860 回答
1

尝试这个:

[UIDevice currentDevice].systemVersion
于 2011-11-04T20:17:22.487 回答