加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Interface Builder,@IBOutlet和Swift中委托和dataSource的协议

发布时间:2020-12-14 05:56:26 所属栏目:百科 来源:网络整理
导读:在Interface Builder中无法将CustomView的委托属性声明为@IBOutlet toViewController – 根本无法建立连接。 这是代码 class CustomView: UIView { @IBOutlet var delegate: CustomViewDelegate?}@objc protocol CustomViewDelegate { ...}class ViewControl
在Interface Builder中无法将CustomView的委托属性声明为@IBOutlet toViewController – 根本无法建立连接。

这是代码

class CustomView: UIView {
     @IBOutlet var delegate: CustomViewDelegate?
}

@objc protocol CustomViewDelegate {
     ...
}


class ViewController: UIViewController,CustomViewDelegate {
     ...
}

使用@objc因为swift protocol,IBOutlet property cannot have non-object type,不知道为什么协议CustomViewDelegate:class {}不起作用。

还有人碰到过这样的东西吗?

从Xcode发行说明:

Interface Builder does not support connecting to an outlet in a Swift file when the outlet’s type is a protocol.

Workaround: Declare the outlet’s type as AnyObject or NSObject,connect objects to the outlet using Interface Builder,then change the outlet’s type back to the protocol.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读