This is the delegate
@protocol DropControllerDelegate;
@interface DropController : NSObject
id<DropControllerDelegate> delegate;
}
@property (nonatomic, assign) id<DropControllerDelegate> delegate;
+ (DropController*) sharedController;
@protocol DropControllerDelegate <NSObject>
- (void)openUserButtons;
- (void)startUpload;
- (void)uploadDone;
- (void)uploadFailed;
- (void)startDownload;
- (void)downloadDone;
- (void)subFolderLoaded;
@end
This is the singleton code:
static DropController *sharedCont = nil;
#pragma mark Singleton stuff
+ (DropController *) sharedController {
@synchronized(self) {
if (!sharedCont)
sharedCont = [[DropController alloc] init];
return sharedCont;
}
return sharedCont;
}
The code to set the delegate is (in both myControllerA and myControllerB):
DropController* dropHelper = [DropController sharedController];
dropHelper.delegate = self;
I’m able to receive the calls in one controller but not in the other controller (the code is a copycat), this is driving me crazy!
As i said in my comment, since you are using a shared instance of that object, it will overwrite the previously set delegate to the new object. So i would suggest to hold a array in your sharedController. Add objects to that array which will want to become the delegates to the sharedController.
Then iterate through that array and call the method over each object in it. Its pretty simple.
Edit:
When you assign the delegate in your
viewcontroller Awith the statementdropHelper.delegate = self;object A becomes the delegate. Calling the method[delegate openUserButtons];will trigger the method inviewcontroller A. But when you dodropHelper.delegate = self;in viewcontroller B,[delegate openUserButtons];will call the method in object B. It will not call both the methods from a and b. Since there is only one delegate variable and you are using a shared singleton object.