BDGapps
BDGapps

Reputation: 3356

Storyboards and Delegates

In my application I am using storyboards, this is how it's set up:

UIViewController ->pushing to -> UIViewController ->pushing to -> UIViewController

I have it all working but I can't figure out how I do the delegate between the firstViewController and the thirdViewController. I have looked at how it would normally be done with storyboards (setting the destinationView delegate) but I somehow need to set the thirdViewControllers delegate not the second one. Because there is the ViewController in-between, I don't know how this is done. Any responces are appreciated.Thank You in advance.

Upvotes: 1

Views: 134

Answers (1)

danh
danh

Reputation: 62676

Do you mean that you'd like the VC1 to be the delegate of VC2 and VC3?

In VC1 prepareForSegue, you can do as you suggest:

VC2 *myVC2 = segue.destinationViewController;
myVC2.delegate = self;

In VC2 prepareForSegue, you can also do as you suggest, only indirectly:

VC3 *myVC3 = segue.destinationViewController;
myV3.delegate = self.delegate;

The headers will look like this:

VC1.h

@protocol VC23Delegate <NSObject>
- (void)doSomethingForVC2;
- (void)doSomethingForVC3;
@end

VC2.h

@protocol VC23Delegate;
@property(weak,nonatomic) id<VC23Delegate> delegate;

VC3.h

@property(weak,nonatomic) id<VC23Delegate> delegate;

Upvotes: 2

Related Questions