Reputation: 9830
I have three viewControllers
. When I'm on the third view controller I want to send a message to the first one. I'm using a protocol
and trying to set the delegate
for this.
viewControllerC.h
@protocol ViewControllerCDelegate
- (void)performAction;
@end
...
@property (nonatomic, strong) id<ViewControllerCDelegate> delegate;
viewControllerA.h
@interface ViewControllerA : UIViewController <ViewControllerCDelegate>
viewControllerA.m
...
- (void)performAction {
NSLog(@"Action was performed");
}
So the only problem is, I can't set the delegate
from the third to the first. How can I set viewControllerC's
delegate to viewControlerA
?
Here's an image to describe it:
Upvotes: 1
Views: 584
Reputation: 394
You'd have to pass along the A controller through to the B controller to be set as the delegate for C when it is created. Kind of messy.
In this case though it might make more sense to use a notification model where Controller A listens for a NSNotification that the action was completed on C.
Upvotes: 3