@IBDesignable崩溃代理 [英] @IBDesignable crashing agent

查看:101
本文介绍了@IBDesignable崩溃代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写自己的 UIButton -extended类并将其设为 @IBDesignable 时,我在接口中收到两个错误构建器,即:

When I write my own UIButton-extended class and make it @IBDesignable, I receive two errors in Interface Builder, namely:


  • Main.storyboard:错误:IB Designables:无法更新自动布局状态:代理崩溃,因为fd已关闭

  • Main.storyboard:错误:IB Designables:无法呈现RandjeUIButton的实例:代理程序崩溃

这是我的代码:

import UIKit

@IBDesignable
class RandjeUIButton: UIButton {
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.backgroundColor = UIColor.blackColor()
    }
}

我在OS X 10.11 beta 2上使用Xcode 7 beta 2。(运行在虚拟机中)

I am working in Xcode 7 beta 2 on OS X 10.11 beta 2. (Running in VM)

推荐答案

Xcode的Interface Builder要求您实施 ini适用于 @IBDesignable 的类,可在IB中正确呈现。

Xcode's Interface Builder requires that you implement both or neither initializers for @IBDesignable classes to render properly in IB.

如果你实现必需的init(编码器aDecoder:NSCoder)你需要覆盖 init(frame:CGRect),否则代理会崩溃,如Xcode抛出的错误所示。

If you implement required init(coder aDecoder: NSCoder) you'll need to override init(frame: CGRect) as well, otherwise "the agent will crash" as seen in the errors thrown by Xcode.

待办事项所以将以下代码添加到您的类中:

To do so add the following code to your class:

override init(frame: CGRect) {
    super.init(frame: frame)
}

这篇关于@IBDesignable崩溃代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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