I'm setting up inheritance.
I have a parent class that has a method that calls a block. Once the block returns, I need it to call an over-written method in the child class.
When I setup breakpoints, upon failure, the block is calling the method in the parent class. What am I doing wrong? Thanks.
Parent Class
.h
@interface BaseClass : UITableViewController
-(void)userModelUpdated
-(void)updateModel
@end
.m
@implementation BaseClass
-(void)userModelUpdated
{} //this is left blank intentionally as a hook
-(void)updateModel
{
//Here is s Block
[EndPoint updateUserModel:self.userModel successBlock:^{
//Do Something
} errorBlock:^(NSError *error, NSArray *errorArray) {
[self userModelUpdated]; // I want to call the method in the child class
// but when I setup the break points, it calls the method in the parent class
}
}
Child Class
.h
@interface childClass : BaseClass
.m
@implementation ChildClass
-(void)viewWillAppear:(BOOL)animated
{
[self updateModel];
}
-(void)userModelUpdated
{
// update UILabels Here
}
If self is an instance of ChildClass when updateModel is invoked, then the ChildClass's implementation of -userModelUpdated will be executed.
If it isn't, then it is because you probably have an instance of BaseClass or you have a misspelling.
Add this to all methods:
NSLog(@"%s", __PRETTY_FUNCTION__);
That'll log exactly what is going on at every step of the way.
It sounds like your code that is creating an instance of this class family is wrong, and is creating a base class object instead of a child class object. Post the code that creates the object and invokes the method on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With