最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】swift代码出错:Initializer does not override a designated initializer from its superclass

Swift crifan 4168浏览 0评论

代码:

import UIKit

class MessageBubbleView: UIView {

    overrideinit(frame: CGRect, message:Message) {
        self.message = message
        bubbleImageView =
       
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

出错:

Initializer does not override a designated initializer from its superclass

如图:

Initializer does not override a designated initializer from its superclass

 

想要搞懂:

到底如何写init函数

ios – Initializer does not override a designated initializer from its superclass – Stack Overflow

swift – Build error when trying to override an initializer in Xcode 6.3 Beta 3 – Stack Overflow

最后用:

import UIKit

class MessageBubbleView: UIView {
   
    var message:Message? = nil
    var displayTextView:UITextView? = nil
    var bubbleImageView:UIImageView? = nil
   
    let font:UIFont? = nil
   
   
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
   
    convenience init(frame: CGRect, message: Message) {
        self.init(frame: frame)
       
        self.message = message
       
        bubbleImageView = UIImageView()
        self.addSubview(bubbleImageView!)
       
        displayTextView = UITextView()
        displayTextView!.textColor = UIColor(white: 0.143, alpha: 1.0)
        displayTextView!.backgroundColor = UIColor.clearColor()
        displayTextView!.selectable = false
        displayTextView!.font = UIFont.systemFontOfSize(12)
        self.addSubview(displayTextView!)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
   
}

才通过编译。

转载请注明:在路上 » 【已解决】swift代码出错:Initializer does not override a designated initializer from its superclass

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
48 queries in 0.113 seconds, using 18.68MB memory