How to implements protocol and delegates in Xamarin iOS

RamohanRamohan Member ✭✭

Hi All,

How to implement class VC2 to VC1 data passing in Xamarin iOS.

Thanks & Regards
Ramohan Reddy

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Firstly, customize the delegate with parameters you want in the class VC2:

    public delegate void MyDelegate(object sender, string args);
    public event MyDelegate MyEvent;
    

    Then register it when you push to VC2 in VC1:

    SecondViewController secondVC = Storyboard.InstantiateViewController("SecondViewController") as SecondViewController;
    secondVC.MyEvent += (sender, args) =>
    {
    
    };
    NavigationController.PushViewController(secondVC, true);
    

    At last, pass the data when you want to come back to VC1:

    MyEvent(this, "other paramters");
    NavigationController.PopViewController(true);
    
  • RamohanRamohan Member ✭✭

    Thank you
    @LandLu

  • LandLuLandLu Member, Xamarin Team Xamurai

    Hi, @Ramohan Did it solve your issues?

  • RamohanRamohan Member ✭✭

    @LandLu said:
    Hi, @Ramohan Did it solve your issues?

    Solved @LandLu

  • LandLuLandLu Member, Xamarin Team Xamurai

    @Ramohan Try to accept it as an answer if you felt it helped. This will also help other community members solve the same kind of issues.

Sign In or Register to comment.