How to deal with delegate method calling back the object who send the message ?

Posted by olipion on Stack Overflow See other posts from Stack Overflow or by olipion
Published on 2010-04-16T22:31:25Z Indexed on 2010/04/16 22:43 UTC
Read the original article Hit count: 137

Filed under:
|

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]; ?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about delegate