Ios Super.init不是';t在从初始值设定项返回之前调用

Ios Super.init不是';t在从初始值设定项返回之前调用,ios,uitableview,error-handling,swift2,xcode7,Ios,Uitableview,Error Handling,Swift2,Xcode7,我试图给我的UITableViewCell类一个自定义初始化器,但我不知道我做错了什么 这是我的密码: init(dataObject: [NSManagedObject]!, objectAttributeValues: [String]!,placeholder: String!, segmentedControl: UISegmentedControl?, cellHeight: CGRect, cellWidth: CGRect) { self.dataObject = data

我试图给我的UITableViewCell类一个自定义初始化器,但我不知道我做错了什么

这是我的密码:

init(dataObject: [NSManagedObject]!, objectAttributeValues: [String]!,placeholder: String!, segmentedControl: UISegmentedControl?, cellHeight: CGRect, cellWidth: CGRect) {
    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")
}
我试图调用super.init(frame:CGRect(…),但通过实现它,我得到了另一个错误:必须调用超类“UITableViewCell”的指定初始值设定项

我能做什么?
多谢各位

初始化器的工作方式是,它们将自己的属性、常量和函数添加到该实例中,然后为其类型的对象调用超类。更多信息

因此,在退出初始化器之前,必须调用超类的“初始化器”。在这里,我建议您在初始化器的最后一行调用
super.init()
。您可以选择
UITableViewCell
上的
init
方法中最合适的方法

    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")
    }

我希望这将帮助您

您必须调用指定初始值设定项的超类

例如,我试图创建
UIView
的子类,但遇到了与您完全相同的问题。
UIView
的指定初始值设定项是
super.init(frame:CGRect)
对于
UITableViewCell
,指定的初始值设定项如下所示

// 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;

希望这有所帮助。

如果调用“super.init()”,将出现错误“必须调用超类“UITableViewCell”的指定初始化器…您必须调用其他初始化器之一,具体取决于您要执行的操作。检查自动完成以了解更多信息。