Xamarin iOS Unwind Segue or DismissViewController programmatically and passes data

I created a sega in my storyboard. This is a modal segment, and I gave it the LoginSegue identifier.

In my controller, I:

PerformSegue("LoginSegue", this);

Things are good. The new controller fits as expected.

To return to the calling view, I can use the unwind by dragging the decoupling button in the calling controller. It works great.

Or I can call (from code):

DismissViewController(true, null);

The fact is that I want to transfer some data.

ParentViewController is null.

I need to do some validation before I get back to the calling view, so automatically disconnecting from the button is not an option.

   [Action("UnwindToCaller:")]
   public void UnwindToCaller(UIStoryboardSegue seque)
   {
       var loginViewController = (LoginViewController)seque.SourceViewController;
       var data = loginViewController.getData();
       Console.WriteLine("Unwind to Caller Here.");
   }

I also cannot find a way to give the segue U-Turn the storyboard identifier.

segue , , DismissViewController, .

, .

+4
1

, . , .

, , , . , .

Xamarin: http://developer.xamarin.com/recipes/ios/general/storyboard/storyboard_a_tableview/

public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
   {
       if (segue.Identifier == "LoginSegue")
       {
           var destCtrl = segue.DestinationViewController as LoginViewController;
           if (destCtrl != null)
           {
               // pass in a reference to THIS view controller.
               destCtrl.SetData(this);
           }
       }
       base.PrepareForSegue(segue, sender);
   }

   public void LoggedIn (string someFlag)
   {
       Console.WriteLine("Logged in with : " + someFlag);
       DismissViewController(true, null);
   }

LoginViewController

public void SetData (CallingViewController callingCtrl)
    {
        calllingViewController = callingCtrl;
    }

Then when I am ready to return.

callingViewController.LoggedIn("the flag"); 
+1
source

Source: https://habr.com/ru/post/1568560/


All Articles