Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

ios - Perform Segue programmatically and pass parameters to the destination view

in my app I've a button that performs a segue programmatically:

- (void)myButtonMethod
{
    //execute segue programmatically
    [self performSegueWithIdentifier: @"MySegue" sender: self];
}

I would like to know if there is a way to reference the destination view and to pass it some parameters.

I know that in prepareForSegue method, I can refer to it with:myDestinationViewController *vc = [segue destinationViewController];, but I don't know how to this executing the segue programmatically.

Do you have any ideas?

Thanks, yassa


UPDATE:

I'm sorry for this question!!! I simply discovered that, even if the segue is invoked programmatically, the prepareForSegue method is called anyway and so it is possible to pass parameters in the same usual way.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The answer is simply that it makes no difference how the segue is triggered.

The prepareForSegue:sender: method is called in any case and this is where you pass your parameters across.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...