userMod2
userMod2

Reputation: 8960

iOS Protocol Method Not Called with Storyboard Segue

I'm passing an array back from one view controller to another.

I'm doing this using protocol and delegate.

The issue i'm facing is if I use the prepareForSegue method that delegate method is not called. But if i create a custom button then use

[self.navigationController pushViewController:bController animated:YES];

on going back to the view controller where I'm passing that array to the method is accessed.

How do i resolve this? i.e. If i place the following chunk of code into my custom next button, how do i identify that word segue (which comes from prepareFromSegue)?

if([segue.identifier isEqualToString:@"page2topage3"]){ ... }

Upvotes: 0

Views: 255

Answers (2)

sunkehappy
sunkehappy

Reputation: 9091

- (IBAction)doneButtonClicked:(id)sender
{
    [self performSegueWithIdentifier:kFromCardListToCardDetailViewControllerIdentifier sender:self];
}

#pragma mark - segue methods

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:kFromCardListToCardDetailViewControllerIdentifier]) {
        MyCardViewController *cardViewController = segue.destinationViewController;
        cardViewController.card = self.cardArray[self.lastSelectedRow];
    }
}

Upvotes: 0

Puneet Sharma
Puneet Sharma

Reputation: 9484

Suppose you have defined a delegate property in ViewController A and you want ViewController B to act as a delegate to A. Then instanceOfViewControllerA.delegate = instanceOfViewControllerB.

In Storyboard, lets say you are going from A to B through segue.

In prepareForSegue method in ViewControllerA class,

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ViewControllerB *instanceOfViewControllerB = segue.destinationViewController;
    self.delegate = instanceOfViewControllerB;
}

Upvotes: 2

Related Questions