无法在Xcode中连接IBAction [英] Can't connect IBAction in Xcode

查看:214
本文介绍了无法在Xcode中连接IBAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从故事板上的按钮拖动到我的视图控制器Swift文件时,我只能选择插入Outlet或Outlet Collection。

When I drag from a button on the storyboard to my view controller Swift file, I only get the option to insert an Outlet or Outlet Collection.

同样,如果我手动创建IBAction并尝试将其连接到故事板上的按钮,我无法连接这两个。

Similarly, if I create the IBAction manually and try to connect it to a button on the storyboard, I can't connect the two.

此问题仅出现在我的一个项目中,但它发生在我项目中的所有故事板上。

This problem is only appears in one of my projects, but it happens on all the storyboards in my project.

看起来像Xcode错误,但也许有人知道解决方法。

Seems like an Xcode bug, but maybe someone knows of a workaround.

(这很难说,但截图中拖动的元素是一个按钮。)

(It's hard to tell, but the element being dragged in the screenshot is a button.)

推荐答案

我的问题非常相似在我的Swift项目中,这让我很生气。

I have very similar issue in my Swift project that was driving me mad.

这就是在 UIButton 拥有 @IBInspectable 属性。更多细节如下。

It turned that's it is the problem of mixing custom protocol adoption in extension of UIButton having @IBInspectable property. More details below.

我终于发现这是因为我的项目中有以下代码:
(版权归Kevin McNeigh所有: https://www.iphonelife.com/blog/31369/swift-programming-101-mastering- dynamic-type-ios

I finally found out that's because I have following code in my project: (copyright goes to Kevin McNeigh: https://www.iphonelife.com/blog/31369/swift-programming-101-mastering-dynamic-type-ios)

protocol DynamicTypeChangeHandler {

    var typeObserver: Bool {get set}
}

extension UIButton: DynamicTypeChangeHandler {
    @IBInspectable var typeObserver: Bool {
        // ...
    }
}

如果我从扩展名或@IBInspectable关键字中删除协议采用,我可以再次设置操作Interface Builder。纯粹的疯狂。 Xcode< 3

If I remove either protocol adoption from the extension or @IBInspectable keyword, I can again setup actions in Interface Builder. Sheer lunacy. Xcode <3

这篇关于无法在Xcode中连接IBAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆