Wednesday, 18 September 2013

_delegate respondsToSelector:selector is not calling the method

_delegate respondsToSelector:selector is not calling the method

I have one class and one view controller. class has _delegate
respondsToSelector:selector. But it is not calling the method(selector).
After viewing my code below, would you please tell what am I doing wrong.
FYI, This code worked before, but suddenly stopped working.
MyClass.h:
@protocol MyClassDelegate <NSObject>
@optional
-(void) receivedEvent:(TripEvent *) event;
@end
@interface MyClass : NSObject<MyClassEngine>
@property(assign) id<MyClassDelegate> delegate;
@property BOOL delegateOnMainThread;
-(id) initWithDelegate:(id<UbiTripRecorderDelegate>) tripDelegate
onMainThread:(BOOL) onMainThread;
- (void) dispatchDelegate:(SEL)selector
withObject:(id)obj;
MyClass.m contains the following code:
#import "MyClass.h"
@implementation MyClass
....
....
-(void) startPlaying {
[self dispatchDelegate:@selector(receivedEvent:) withObject:newEvent];
}
- (void) dispatchDelegate:(SEL)selector withObject:(id)obj {
@try {
if(_delegate && [_delegate respondsToSelector:selector]) {
NSLog(@"I can't come to this point");
}
}
}
I've also added the following code in my view controller:
@interface MyViewController : BaseViewController<MyClassDelegate>
The problem is that the if(_delegate && [_delegate
respondsToSelector:selector]) - logic never return true. Can anybody
please check the code and let me know, if anything is wrong with my code?

No comments:

Post a Comment