ycs.lrodz
ycs.lrodz

Reputation: 47

Return data from another view Xamarin.iOS

What I'm currently trying to do sounds simple however I haven't seen a good example or been able to find one.

I'm currently adding a view to the navigation controller the following way:

ViewControllers.CompaniesViewController companiesViewCtrl = this.Storyboard.InstantiateViewController ("companySelectView") as ViewControllers.CompaniesViewController;
this.NavigationController.PushViewController(companiesViewCtrl, true);

It will bring up a view with a list of companies and all I need to do is as soon as the user selects a company, I'll store some information (I already do this) but return it to the previous view and do something and maybe run an event. Can anyone point me in the right direction how to do this?

Thanks :)

Upvotes: 2

Views: 270

Answers (1)

Giorgi
Giorgi

Reputation: 30883

The simplest solution is to add an event to CompaniesViewController and raise it when user selects a company. The navigation controller that pushed the companiesViewCtrl can subscribe to the event and will get notified when company is selected.

class CompaniesViewController
{
    public event Action<Company> CompanySelected;

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        //Raise CompanySelected event if it isn't null and pass selected company.
    }
}

All you have to do now is subscribe to CompanySelected event before pushing the controller.

Upvotes: 1

Related Questions