Forum Xamarin.iOS

PresentViewController Completion handler parameter

PiratePirate SAMember ✭✭

I want to pass callback method in the last parameter of PresentViewController of a UIViewController but I can't figure it out . Can anyone help me please ?

Kindly monotouch code c# .

thanks

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    You mean like this?

    public void ViewController1
    {
        private void PresentOtherViewController()
        {
            PresentViewController(new ViewController2(), animated: true, completionHandler: PresentationFinished);
        }
    
        private void PresentationFinished()
        {
            // ...
        }
    }
    

    You can also use a lambda:

        private void PresentOtherViewController()
        {
            PresentViewController(new ViewController2(), animated: true, completionHandler: () =>
            {
                // ...
            });
        }
    

    In case you're confused, this method is called when the animation is complete, not when the presented view controller is dismissed. You have to provide your own events to be notified when a view controller is dismissed, but it's best to keep that code in the same class that did the presentation anyway.

  • PiratePirate SAMember ✭✭

    Thanks Adam ...I was confused about NSAction , I didn't know I can only pass a method .

Sign In or Register to comment.