zoukankan      html  css  js  c++  java
  • required 引发的小小思考

    原创:转载请注明出处

    首先,因为遇到问题如下:

    class MainTabBar: UITabBar {

        override init(frame: CGRect) {

            super.init(frame: frame)

            self.translucent = false

            self.backgroundImage = UIImage(named: "tabbar")

        }

    //    //在子类重写父类的必要构造器时,必须在子类的构造器前也添加required修饰符,表明该构造器要求也应用于继承链后面的子类。

        required init?(coder aDecoder: NSCoder) {

            super.init(coder: aDecoder)

     

        }

    }

     

    继承关系链:

    UITabBar -> UIView -> 

    public class UIView : UIResponder, NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace, UIFocusEnvironment 

     

    好,在UITabBar、UIView 中init方法并没有显示写出  Required

     

    原因在此:

     

    If you override any of a class's designated initializers, you don't inherit any other designated initializers. But UIView adopts the NSCoding protocol, which requires an init(coder:)initializer. So you must implement that one too:

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

     

     

    By the way: Xcode 会提示自动补全代码  

     

     

    参考链接:

    1.http://stackoverflow.com/questions/26081287/required-initializer-initcoder-must-be-provided-by-subclass-of-uitablevi

    2.https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_307

  • 相关阅读:
    js 数组分解 解构
    js math 对数和指数处理 expm1 log1p
    highcharts 坐标轴 数值 格式化
    libvirt-qemu-虚拟机设备热插拔
    Linux设备驱动程序加载/卸载方法 insmod和modprobe命令
    mount、umount、fuser命令使用小结
    Linux安全策略配置-pam_tally2身份验证模块
    python处理时间相关的方法
    python中命令行参数
    linux---(6/27)tr命令和sed命令详解
  • 原文地址:https://www.cnblogs.com/Jenaral/p/5531855.html
Copyright © 2011-2022 走看看