【问题标题】:UIButton stop showing UIControl actions in interface builder after adding extension to itUIButton 在向其添加扩展后停止在界面构建器中显示 UIControl 操作
【发布时间】:2017-05-29 01:22:42
【问题描述】:

我有最简单的用户界面——只有一个按钮:

如您所见,我可以将任何事件(如 UITouchUpInside)从界面生成器拖到我的代码中。

但是如果我向 UIButton 添加一些扩展,例如:

protocol SomeProtocol {}

extension UIButton: SomeProtocol {}

那些事件不再可见:

我使用的是 Xcode 版本 8.2 (8C38)

我可以以某种方式退回它们吗?这是 Xcode 中的错误吗?

【问题讨论】:

    标签: ios swift uibutton interface-builder protocol-extension


    【解决方案1】:

    我遇到了一个类似的问题,我无法将自定义类链接到网点和 IBAction。 在我的例子中,我必须使用标准的 UIKit 类将我的对象链接到 IBOutlet,然后我修改了代码以满足我的需要。

    【讨论】:

      【解决方案2】:

      这似乎是一个 Xcode 错误。

      您可以尝试的解决方法是使用协议扩展 UIControl。 UIControl 是 UIButton 的超类,所以对 UIControl 的扩展 由 UIButton 继承,当一个 UIControl采用的协议。

      protocol SomeProtocol { }
      
      extension UIControl: SomeProtocol { }
      

      来自 Apple 开发者论坛

      Adding a Swift protocol to UIButton breaks Interface Builder action options.

      【讨论】:

        猜你喜欢
        • 2010-10-08
        • 1970-01-01
        • 2020-09-03
        • 2014-05-14
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多