2

我已经阅读了大约 10 篇文章,但没有发现我的实现有什么问题。

这个应用程序是用 iOS 6 编写的,但更新到 iOS7,所以我想同时支持 iOS6 和 iOS7。但是,如果我在 iOS6 设备上运行仅限 iOS7 的方法,它就会中断。所以我想添加responsToSelector,检查它上面有iOS7,但由于某种原因,if总是返回false。

AppDelegate.m:

if ([[UINavigationBar appearance] respondsToSelector:@selector(shadowImage)])

if ([[UINavigationBar appearance] respondsToSelector:@selector(setShadowImage:)])

有人可以告诉我我做错了什么吗?

编辑:我尝试将部署目标设置为 iOS6 和 iOS7,两种情况都返回 false。

Edit2:如果我删除 if 语句并调用该方法,它会在 iOS7 中按预期工作。

4

1 回答 1

2

而不是查询[UINavigationBar appearance]选择器,只是

[UINavigationBar instancesRespondToSelector:@selector(shadowImage)]

另一种解决方案可能是检查 iOS 版本

if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
    NSLog(@"iOS >= 7.0");
于 2013-09-23T07:26:53.790 回答