I have created a base class(BaseClassViewController) having two to three method in it(as seen in image). I have called this method from viewDidLoad as I want it to be called by every subclass object. After that I have created subclass of BaseClassViewController(SubclassViewController). As I told earlier I want to call all the super class method from current subclass I added following code with other method. I run the project and expect the following logs But I received the following logs The reason behind why I get that logs is, I have the same method named [- (void)setup] in both base class and subclass. When [super viewDidLoad] of subclass called the controller goes the “viewDidLoad” of base class and call the methods line vice. when it comes to [self setup] it call the [- (void)setup] of subclass because here “self” represent the SubclassViewController not the BaseClassViewController. So, to get the desire logs/result simply rename the method name I prefer to change the method name from SubclassViewController you may change the BaseClassViewController also. Result Note: Just keep in mind that subclass don’t have the same named method or properties the base class had as it override the base class method or properties and we don’t get the desire results.
0 Comments
|
Archives |