Why do both init functions get called

后端 未结 1 557
情话喂你
情话喂你 2021-01-13 22:35

If I have a class that is setup like this to customize a UIView.

@interface myView : UIView

- (id)init {
    self = [super init];
    if(self){
             


        
1条回答
  •  野的像风
    2021-01-13 23:27

    UIView init calls UIView initWithFrame:. Since you override both, calling your init method results in your initWithFrame: method being called:

    In other words: your init calls UIView init. UIView init calls initWithFrame:. Since you override initWithFrame:, your initWithFrame: is called which in turn calls UIView initWithFrame:.

    The solution, since your initWithFrame: will always be called, is to remove the call to foo from your init method.

    0 讨论(0)
提交回复
热议问题