将子类添加到Storyboard崩溃

将子类添加到Storyboard崩溃

本文介绍了将子类添加到Storyboard崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的UIView类:

This is my class of a UIView:

class overlap: UIView{
    init() {
        super.init(frame: UIScreen.main.bounds)
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        fatalError("init(coder:) has not been implemented")
    }
}



It should just fill up the screen. When I add the view in Storyboard with constraints pinned to the edges of the screen, it crashes when I launch the app. The error comes up as stated in the code above.

以编程方式创建和添加子类与此init函数一起使用:

Creating and adding the subclass programmatically works with this init function:

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

但我希望它可以通过Storyboard重复使用,而无需添加代码。我的代码有什么问题,它甚至可能是我想要的吗?

But I want it reusable through Storyboard, without adding code. What is wrong with my code, and is it even possible what I want?

谢谢!

推荐答案

因为这就是你的代码告诉它要做。

Because that is what your code told it to do.

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    fatalError("init(coder:) has not been implemented")
}

fatalError 表示让我崩溃。

这篇关于将子类添加到Storyboard崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:33