最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Swift crifan 9692浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

    87 queries in 0.164 seconds, using 22.06MB memory