我很困惑与[UIView的INIT]和[UIView的initWithFrame:方法XX],之后我搜索计算器,我发现下面的问题和答案:iOS:UIView子类init会调用[super init],然后调用超类中的方法,为什么它会调用[subclass initWithFrame:xx]?
Why do both init functions get called
iOS: UIView subclass init or initWithFrame:? 然后我konw的initwithFrame是设计初始值设定项,当我们调用[myview init](myView是UIView的子类并覆盖init和initwithfrme :)时,它会调用call [super init],然后它会调用[super initWithFrame:xx] as super会在超类中找到方法,为什么它会调用[myView initWithFrame:xx] ???
感谢您的帮助。我可以看到它。什么让我感到困惑是我在其他问题中发现我列出的答案是[YourClass init] - > [super init] - > [YourClass initWithFrame] - > [super initWithFrame:CGRectZero],它会调用子类的initWithFrame然后调用超类,这让我感到困惑?为什么要调用[YourClass initWithFrime:XX]? – Luca
我更新了我的答案,真的会发生什么是[超级初始化]调用[self initWithFrame] ...这是什么触发[YourClass initwithFrame:],然后调用[super initWithFrame:] –
是的,如果它是那么答案应该是。但为什么“[super init]调用[self initWithFrame]”,因为我们知道super是魔术字告诉编译器在超类中查找方法,所以应该“[super init]调用[super initWithFrame]”??? – Luca