【问题标题】:UIBarButtonItem nextResponder callUIBarButtonItem nextResponder 调用
【发布时间】:2013-07-25 18:18:18
【问题描述】:

在网上看(https://github.com/Musixmatchdev/ObjectiveHeaders/blob/master/Headers/iPhoneOS6.0.sdk/UIKit/UIBarButtonItem.h)发现UIBarButtonItem实现了nextResponder选择器。

但是,这不是 UIBarButtonItem 的公共 API 的一部分,而是在 UIResponder 类中(遗憾的是 UIBarButtonItem 没有继承自该类)。

我被授权使用它还是被 Apple 拒绝? (我会在 Apple 论坛上询问,但我相信它会下降一段时间:)

非常感谢,

杰克·帕舍

【问题讨论】:

    标签: ios uibarbuttonitem


    【解决方案1】:

    遗憾的是,UIBarButtonItem 是基于残缺的 UIBarItem,并且它们都没有实现 nextResponder 方法。因此,它被视为私有(非公共)API,并且根据Apple App Store review guideline pt.2.5,“使用非公共 API 的应用程序将被拒绝”。

    注意:Apple 开发者门户现已关闭,但可以在网上轻松找到指南

    附:请描述使用 UIBarButtonItem 的 nextResponder 的原因 - 我确信有不止一种方法可以实现它。

    【讨论】:

    • 我想代理 UIBarButtonItem 上的操作/目标,以便在触发(或不触发)用户设置的实际操作/目标之前对其进行一些检查条件。但是在这种情况下,响应者链不会处理 nil 目标
    • UIBarButtonItem 的私有 nextResponder 指向 UINavigationBar。由于 UINavigationBar 是基于 UIResponder 的,它的 nextResponder 是公开的,你完全可以合法地在那里处理你的检查。
    • 注意:没有人可以100% 保证您创建的每个UIBarButtonItem 的nextResponder 将始终指向它的UINavigationBar。然而,由于这一事实完全符合 Apple 的响应者链设计模式,我认为在生产中使用它是安全的。
    【解决方案2】:

    好的,我找到了针对我的特定问题的解决方案:

    我将调用转发到 [[UIApplication sharedApplication] sendAction:to:from:forEvent:]] 选择器,然后(使用 from 参数)使用 UIBarButtonItem nextResponder。所以这是使用公共 API 对它的间接引用。

    但是我认为 Apple 只是在此方法中的 id 参数上使用了 respondsToSelector:@selector(nextResponder)。因此,在自定义代码中做同样的事情(编写一个采用 id 参数然后调用 nextResponder 的方法)也可能是使用 nextResponder 选择器的解决方案,但不会被视为使用私有 API,但这只是一个假设。

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多