Is calling super in a category the same as calling it in a subclass?

后端 未结 4 1431
野性不改
野性不改 2020-11-30 09:26

Does calling [super init] do the same thing in a category as a subclass? If not, what\'s the difference?

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 09:42

    Given the below example, super will call UIView init (not UINavigationBar init method)

    @implementation UINavigationBar (ShadowBar)
    - (void)drawRect:(CGRect)rect {
        //draw the shadow ui nav bar
        [super init];
    }
    @end
    

    If you subclass it, [super init] will call UINavigationBar init method.

    So yes, if there are additional things you will do in UINavigationBar init (extra from UIView) they do different things.

提交回复
热议问题