Search code examples
iosobjective-ccocoansnotificationcenternsnotification

NSNotificationCenter calling methods from super class or subclass?


I have a view controller B which is subclass of A.I have registered for a notification named kMyNotificaitonName in in A’s ViewWillAppear like this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MyNotificaitonNameHandler:) name: kMyNotificaitonName object:nil];

I have implemented MyNotificaitonNameHandler in view controller A and B which method will get called?


Solution

  • It depends on the particular object. If you've created an instance of A it will be A. And otherwise. Since your B class provides implementation of MyNotificaitonNameHandler and you have instance of B then it's B. Pure OOP