不工作UISplitViewController - WillHideViewController没有在monotouch中调用

时间:2013-08-27 08:08:16

标签: ios xamarin.ios uisplitviewcontroller uisplitviewdelegate

我遇到UISplitviewcontroller

的问题

当我创建splitviewcontroller(第一次)时,显示barbutton并且工作正常,

在master中选择表格行后,删除detailview1&添加detailview2,现在没有显示按钮。如果我旋转iPad按钮会显示,

我不知道为什么最初不显示条形按钮。我设置了委托,即使它没有显示按钮。

这是我使用的代码:

        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 }; 
        }

这是detailviewcontroller1detailviewcontroller2中设置的代理。

[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;
    }

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

在您的示例中不会调用

WillHideViewController,因为您在显示新控制器之前设置了WeakDelegate属性。如果你改变了这两个语句的顺序,你就会遇到类似的问题,并且不会调用WillShowViewController

有没有办法可以从单个类处理拆分视图委托?通常我会在UISplitViewController的子类中处理此委托,并且只设置WeakDelegate一次。