Cannot call initializer for type "CustomDetailView" without arguments

An error while trying to do this is simply creating an instance of my custom class

class CustomDetailView: UIImageView {
  let packThumbImage = UIImageView()
  let packFrameImage = UIImageView()
  let packNameLabel = UILabel()

 required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
 }

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

var customPackView = CustomDetailView () // error here

+4
source share
2 answers

By adding the following code to a custom class, the problem is fixed.

 convenience init() {
    let frame:CGRect = CGRect.zero
    self.init(frame: frame)
}
0
source
var customPackView = CustomDetailView(frame: CGRect.zero) 

Change . You do not have an empty initializer. Therefore, you must use an initializer with a parameter.

+2
source

Source: https://habr.com/ru/post/1659702/


All Articles