Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data from PerformSegue in monotouch

I have table source class and on row click I am calling below function to move to another controller but I want to pass some data.

controller.PerformSegue("backtorootviewsague",controller);

Does any knows how can I achieve it. I am new in monotouch and ios. I cannot figure out how to achieve this.

like image 662
Akrambek Avatar asked Sep 07 '12 16:09

Akrambek


People also ask

How do I transfer data from Segue?

Pass Data using Seque. After outlet is connected to respective viewController, select Enter Last Name button and then CTRL + Drag to NextViewController(i.e, FirstViewController) for showing the viewController from LandingPageViewController. This lets you set what kind of segue you want to use.

What is Sender in Perform segue?

performSegue(withIdentifier:sender:)Initiates the segue with the specified identifier from the current view controller's storyboard file.


1 Answers

PrepareForSegue is the right place to do it. For example, if the controller that creates CustomerViewController is called CustomerListViewController, override in CustomerListViewController that method like the following:

public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
    base.PrepareForSegue (segue, sender);

    // do first a control on the Identifier for your segue
    if (segue.Identifier.Equals("your_identifier")) {

        var viewController = (CustomerViewController)segue.DestinationViewController;
        viewController.MyData = dataToInject;
    }
}

where CustomerViewController has a public property like the following:

public SomeTypeData MyData { get; set; }

You could see this in action in Xamarin samples.

Hope that helps.

like image 72
Lorenzo B Avatar answered Oct 08 '22 00:10

Lorenzo B