ios Swift致命错误:使用未实现的初始化器'init()'

时间:2022-09-07 07:54:38

I've been trying very hard, have looked up every similar question pertaining to this issue on * and trying them to no avail.

我一直在努力地尝试,在*上搜索了与这个问题相关的所有类似的问题,但都没有用。

class TimeLineTableViewController: UITableViewController,   
UIImagePickerControllerDelegate, UINavigationControllerDelegate  {

var timelineData = [PFObject]()


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

override func viewDidLoad() {

    super.viewDidLoad()

    self.loadData()     


}
 @IBAction func loadData(){
    timelineData.removeAll(keepCapacity: false)

    var findTimelineData:PFQuery = PFQuery(className:"timelineMessages")
    findTimelineData.findObjectsInBackgroundWithBlock
        {
            (objects:[AnyObject]! , error:NSError!) -> Void in
            if error == nil
            {
                self.timelineData = objects.reverse() as [PFObject]


                //let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects

                // self.timelineData = array as NSMutableArray



                self.tableView.reloadData()
            }
    }
}




override func viewDidAppear(animated: Bool) {



    var footerView:UIView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 50))
    self.tableView.tableFooterView = footerView

    var logoutButton:UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
    logoutButton.frame = CGRectMake(20, 10, 50, 20)
    logoutButton.setTitle("Logout", forState: UIControlState.Normal)
    logoutButton.addTarget(self, action:"logout:", forControlEvents: UIControlEvents.TouchUpInside)

    footerView.addSubview(logoutButton)

}

To clarify, timelineTableViewController has one class that inherits, MessageTableCell. It's also part of a project that I've integrated into Objective-C code, so it's a combination of both Swift and ObjC. I've run both projects (the swift one and the ObjC one) independently and they work fine; it's only when I try to run it together do they mess up. Any suggestions? I'm at an utter loss for this.

为了澄清,timelineTableViewController有一个继承的类,MessageTableCell。它也是我集成到Objective-C代码中的项目的一部分,所以它是Swift和ObjC的结合。我已经独立地运行了两个项目(swift和ObjC),它们工作得很好;只有当我试着一起跑的时候,他们才会搞砸。有什么建议吗?我完全不知道。

1 个解决方案

#1


38  

“Unlike subclasses in Objective-C, Swift subclasses do not inherit their superclass initializers by default.”

“与Objective-C中的子类不同,Swift子类默认不会继承它们的父类初始化器。”

Automatic Initializer Inheritance

自动初始化继承

  • Rule 1: If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers.
  • 规则1:如果您的子类没有定义任何指定的初始化器,它将自动继承其所有的超类指定初始化器。
  • Rule 2: If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.
  • 规则2:如果您的子类提供了所有超类指定初始化的实现,或者按照规则1继承它们,或者提供自定义实现作为其定义的一部分,那么它将自动继承所有超类的便利初始化器。

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/tw/jEUH0.l

摘自:苹果公司“Swift编程语言”。“iBooks。https://itun.es/tw/jEUH0.l

Since you have override the init(coder aDecoder: NSCoder), TimeLineTableViewController won't have the init() initiailzer.

由于您已经重写了init(编码器aDecoder: NSCoder), TimeLineTableViewController将没有init()初始化器。

You can provide an implementation of all of its superclass designated initialisers like this

您可以提供所有父类指定的初始化器的实现,如下所示

override init() {
        super.init()
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

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

, or just delete the implementation of init(coder aDecoder: NSCoder).

,或者只是删除init的实现(编码器加码器:NSCoder)。

#1


38  

“Unlike subclasses in Objective-C, Swift subclasses do not inherit their superclass initializers by default.”

“与Objective-C中的子类不同,Swift子类默认不会继承它们的父类初始化器。”

Automatic Initializer Inheritance

自动初始化继承

  • Rule 1: If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers.
  • 规则1:如果您的子类没有定义任何指定的初始化器,它将自动继承其所有的超类指定初始化器。
  • Rule 2: If your subclass provides an implementation of all of its superclass designated initializers—either by inheriting them as per rule 1, or by providing a custom implementation as part of its definition—then it automatically inherits all of the superclass convenience initializers.
  • 规则2:如果您的子类提供了所有超类指定初始化的实现,或者按照规则1继承它们,或者提供自定义实现作为其定义的一部分,那么它将自动继承所有超类的便利初始化器。

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/tw/jEUH0.l

摘自:苹果公司“Swift编程语言”。“iBooks。https://itun.es/tw/jEUH0.l

Since you have override the init(coder aDecoder: NSCoder), TimeLineTableViewController won't have the init() initiailzer.

由于您已经重写了init(编码器aDecoder: NSCoder), TimeLineTableViewController将没有init()初始化器。

You can provide an implementation of all of its superclass designated initialisers like this

您可以提供所有父类指定的初始化器的实现,如下所示

override init() {
        super.init()
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

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

, or just delete the implementation of init(coder aDecoder: NSCoder).

,或者只是删除init的实现(编码器加码器:NSCoder)。