I am making a program for iOS 7, but because I use nearly the same method in several views, I would like to create a common class which covers the most of the method and uses a callback method for the finishing touch which is separate for every view. I have the following code in the view:
// On top of the view .m
#import "Common.h"
// Method which will be called.
-(void)doSomething
{
NSLog(@"doSomething...");
[Common target:self method:@selector(callbackMethod)];
}
// Method I want to be called.
+(void)callbackMethod
{
NSLog(@"Should come here...");
}
The Common.h is as following:
#import <Foundation/Foundation.h>
@interface Common : NSObject
+(void)target:(Class)object method:(SEL)selector;
@end
The Common.m is as following:
+(void)target:(Class)object method:(SEL)selector
{
NSLog(@"target...");
if ([object respondsToSelector:@selector(selector)])
{
[object performSelector:@selector(selector)];
} else {
NSLog(@"%@", object);
}
}
On runtime, it only outputs: doSomething..., target..., <ParentViewController: 0x8d24bb0>
The problem here is with calling the callback method. The program will reach the method in Common.m but can't call the method from the parent.