Super.init isn't called before returning from initializer
The way initialisers work, is they will add their own properties, constants and functions to that instance, then call back to the superclass for an object of it's type. More info here.
For this reason you must call a superclass' initialiser before exiting the initialiser. Here I suggest you call super.init()
on the last line of your initialiser. You can choose which of the init
methods on UITableViewCell
is most appropriate.
override init(frame: CGRect) { super.init(frame: frame) } convenience init(frame: CGRect, dataObject: [NSManagedObject]!, objectAttributeValues: [String]!,placeholder: String!, segmentedControl: UISegmentedControl?, cellHeight: CGRect, cellWidth: CGRect){ self.init(frame: frame) self.dataObject = dataObject self.Placeholder.text = placeholder self.objectAttributeValues = objectAttributeValues if segmentedControl != nil { self.segmentedControl = segmentedControl! didHaveSegmentedControl = true } } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
I hope this will help you Override init method of UIView in swift
You have to call the superclasses designated initializer.
For example, I tried to create a subclass of UIView
and had the exact same problem you had.The designated initializer for UIView
is super.init(frame: CGRect)
For UITableViewCell
the designated initializers are as follows.
// Designated initializer. If the cell can be reused, you must pass in a reuse identifier. You should use the same reuse identifier for all cells of the same form. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: (nullable NSString *)reuseIdentifier NS_AVAILABLE_IOS(3_0) NS_DESIGNATED_INITIALIZER;- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
Hope this helped.