not working UISplitViewController - WillHideViewController not called in monotouch

972 Views Asked by At

I have problem with UISplitviewcontroller,

When I create splitviewcontroller (first time) shows barbutton and it works fine,

After select table row in master, its remove detailview1 & add detailview2, now the barbutton not shown. if i rotate iPad barbutton will shown,

I don't know why initially not show the bar button. I set delegate, even its not shown the barbutton.

This is the code I used :

        UINavigationController navMaster = appDel.SplitView.ViewControllers [0] as UINavigationController;

        if (indexPath.Row == 0) 
        {  
            ViewController1 View1 = new ViewController1 ();
            UINavigationController nav1 = new UINavigationController (View1); 
            appDel.SplitView.WeakDelegate = View1;              
            appDel.SplitView.ViewControllers = new UIViewController[]{ navMaster, nav1 }; 
        }  
        else if (indexPath.Row == 1) 
        {
            ViewController2 View2 = new ViewController2 ();
            UINavigationController nav2 = new UINavigationController (View2); 
            appDel.SplitView.WeakDelegate = View2;              
            appDel.SplitView.ViewControllers = new UIViewController[]{ navMaster, nav2 }; 
        }

This is the delegate set in detailviewcontroller1 and detailviewcontroller2.

[Export("splitViewController:willHideViewController:withBarButtonItem:forPopoverController:")]
        public void WillHideViewController (UISplitViewController splitController, UIViewController viewController, UIBarButtonItem barButtonItem, UIPopoverController popoverController)
        {
            barButtonItem.Title = "Inputs";
            NavigationItem.SetLeftBarButtonItem (barButtonItem, true);
            masterPopoverController = popoverController;
        }

    [Export("splitViewController:willShowViewController:invalidatingBarButtonItem:")]
    public void WillShowViewController (UISplitViewController svc, UIViewController vc, UIBarButtonItem button)
    {
        NavigationItem.SetLeftBarButtonItem (null, true);
        masterPopoverController = null;
    }

Can any one help me ?

1

There are 1 best solutions below

1
jonathanpeppers On

WillHideViewController will not be called in your example because you set the WeakDelegate property prior to showing the new controller. If you switched the order of those two statements, you'd have a similar problem, and WillShowViewController would not be called.

Is there a way you can handle the split view delegate from a single class? Generally I handle this delegate in a subclass of UISplitViewController and only set WeakDelegate once.