我很困惑與[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