将子类添加到Storyboard崩溃 [英] Adding subclass to Storyboard crashes
问题描述
这是我的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")
}
}
<它应该只是填满屏幕。当我在Storyboard中添加视图并将约束固定到屏幕边缘时,它会在我启动应用程序时崩溃。出现错误,如上面的代码所述。
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?
谢谢!
推荐答案
我启动应用程序时崩溃
it crashes when I launch the app
因为这就是你的代码告诉它要做。
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崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!