【问题标题】:-[UIBarButtonItem setBackgroundImage:forState:style:barMetrics:]: unrecognized selector sent to instance-[UIBarButtonItem setBackgroundImage:forState:style:barMetrics:]: 无法识别的选择器发送到实例
【发布时间】:2013-03-16 09:27:23
【问题描述】:

我开发了一个具有部署目标ios sdk as 6.0的应用程序。后来我的客户要求应用程序应该在 ios 5.0+ 设备中运行。所以我已将部署目标更改为 5.0 并禁用了 IB 的自动布局属性,如堆栈中提到的here,但现在我收到如下所示的错误:

> -[UIBarButtonItem setBackgroundImage:forState:style:barMetrics:]:无法识别的选择器发送到实例 0x2971f0

我没有发现我的 UIBarButtonItem 有什么问题,

 addButton = [[UIBarButtonItem alloc]
        initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
        target:self
        action:@selector(addProject)];

现在我正在努力寻找解决方案,等待您的宝贵帮助.. 提前致谢。

【问题讨论】:

  • 该方法仅适用于iOS 6.0+
  • 我没有使用过类似的方法。这就是我的代码中的内容:- addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProject)] ;
  • 它适用于 iOS 5.0 及更高版本。
  • @ElliottPerry 你应该把它写成答案,因为它是正确的。他需要做responstoselector并拥有两个版本的add按钮。
  • @mvp 你说得对,那行代码应该没有问题。问题一定出在其他地方。你能不能逗我一下,在你的代码库中搜索 setBackgroundImage:forState:style:barMetrics: 方法(显然不要搜索整行文本,因为它会被参数名称和类型分解。尝试搜索“barMetrics”)。

标签: iphone ios5 ios6 uibarbuttonitem


【解决方案1】:

setBackgroundImage:forState:barMetrics: 在 iOS 5.0+ 中可用,但setBackgroundImage:forState:style:barMetrics: 仅在 iOS 6.0+ 中可用

【讨论】:

  • setBackgroundImage:forState:barMetrics: 适用于 iOS 5.0+setBackgroundImage:forState:style:barMetrics: 仅适用于 iOS 6.0+
  • 做一个 if 响应选择器来选择哪一个,而不是基于操作系统版本。这是知道使用哪一个的正确方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 2012-07-24
相关资源
最近更新 更多