respondsToSelector 外观代理失败

respondsToSelector fails for appearance proxy(respondsToSelector 外观代理失败)
本文介绍了respondsToSelector 外观代理失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试通过在 [UIBarButtonItem 外观] 上运行 respondsToSelector 来检测 iOS 6 特定的外观方法.但是,无论我指定什么选择器,它总是为我返回 NO:

I’m trying to detect an iOS 6-specific appearance method, by running respondsToSelector on the [UIBarButtonItem appearance]. However, it always returns NO for me, whatever selector I specify:

// Should show NOPE in iOS 5, YEP in iOS 6. Shows NOPE always
NSLog(@"%@", [[UIBarButtonItem appearance] respondsToSelector:@selector(setBackgroundImage:forState:style:barMetrics:)] ? @"YEP" : @"NOPE"); 

// Should show YEP in both iOS 5 and iOS 6. Shows NOPE always
NSLog(@"%@", [[UIBarButtonItem appearance] respondsToSelector:@selector(setBackgroundImage:forState:barMetrics:)] ? @"YEP" : @"NOPE"); 

实际上,在它们各自的 iOS 版本上使用这些方法都可以正常工作,但我似乎无法检测到哪一个对我可用.那么我该如何正确地做到这一点呢?

Actually using those methods works fine on their respective versions of iOS, but I can’t seem to detect which one is available to me. So how do I properly do that?

推荐答案

不要检查外观代理.你永远不能依赖它,因为它是一个代理.相反,直接检查具有新方法的项目,在这种情况下,UIBarButtonItem:

Don't check the appearance proxy. You can never rely on that, since it's a proxy. Instead, directly check the item that has the new method, in this case, the UIBarButtonItem:

BOOL hasNewMethod = [UIBarButtonItem instancesRespondToSelector:@selector(setBackgroundImage:forState:style:barMetrics:)];
if( hasNewMethod )
  NSLog(@"Running iOS 6 with new method");
else
  NSLog(@"Current OS doesn't support method...");

这篇关于respondsToSelector 外观代理失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

AWS DynamoDB Batch Get Request - iOS(AWS DynamoDB 批量获取请求 - iOS)
DynamoDB auto incremented ID amp; server time (iOS SDK)(DynamoDB 自动递增 ID amp;服务器时间(iOS SDK))
Swift alert view with OK and Cancel: which button tapped?(带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮?)
dynamodb scanexpression with scan filter in objective-c(在objective-c中带有扫描过滤器的dynamodb scanexpression)
Getting full access to DynamoDB from my ios app using AWS Cognito Developer Identities(使用 AWS Cognito 开发人员身份从我的 ios 应用程序获得对 DynamoDB 的完全访问权限)
iOS framework with dependencies(具有依赖项的 iOS 框架)