How to deal with delegate method calling back the object who send the message ?
- by olipion
I have two object:
@protocol ObjectADelegate
- (void)objectAfirst:(ObjectA *)obj;
- (void)objectAsecond:(ObjectA *)obj;
@end
@interface ObjectA : NSObject {
id<ObjectADelegate> delegate;
- (void)callSecond
{
[self.delegate objectAsecond:self];
}
@end
@interface ObjectB : NSObject <ObjectADelegate>{
ObjectA *myObjectA;
}
@implementation ObjectB
- (void)objectAfirst:(ObjectA *)obj
{
// First is finished, do second
[obj callSecond];
}
- (void)objectASecond:(ObjectA *)obj
{
// Do my stuff
}
@end
As you can see in the code, when ObjectA send the message objectAfirst to its delegate, objectb use again objectA methods that result in objecta calling back objectb.
It means that what first fire objectAfirst is not finished but objectA send the objectAsecond message.
Could it be a problem ?
Any way to let delay message handling in objectB ?
for example, something like using
[obj performSelector:@selector(callSecond) afterDelay:0.01];
instead of
[obj callSecond]; ?