コード例 #1
0
ファイル: UIViewExtensions.cs プロジェクト: Zebra/iFactr-iOS
        public static void ConfigureBackButton(this UIViewController controller, Link backLink, Pane outputPane)
        {
            var backButton = new UIBarButtonItem(string.IsNullOrEmpty(controller.NavigationItem.Title) ?
                                                 TouchFactory.Instance.GetResourceString("Back") : controller.NavigationItem.Title, UIBarButtonItemStyle.Plain, null);

            controller.NavigationItem.BackBarButtonItem = backButton;
            controller.NavigationItem.LeftBarButtonItem = null;

            var stack = controller.NavigationController as IHistoryStack ?? PaneManager.Instance.FromNavContext(outputPane, PaneManager.Instance.CurrentTab);

            if (stack != null && !stack.CanGoBack())
            {
                controller.NavigationItem.SetHidesBackButton(true, false);
            }
            else if (backLink == null && controller.NavigationItem.HidesBackButton)
            {
                controller.NavigationItem.HidesBackButton = false;
            }

            if (backLink != null)
            {
                var weak = new WeakReference(controller);
                backButton          = controller.CreateButton(backLink);
                backButton.Clicked += delegate(object sender, EventArgs e)
                {
                    var historyStack = (weak.Target as UIViewController)?.NavigationController as IHistoryStack;
                    if (historyStack != null)
                    {
                        historyStack.HandleBackLink(backLink, outputPane);
                    }
                };

                controller.NavigationItem.SetHidesBackButton(true, false);
                controller.NavigationItem.SetLeftBarButtonItem(backButton, false);
            }

            var popover = controller.NavigationController as PopoverNavigationController;

            if (popover != null)
            {
                popover.SetCloseButton(controller);
            }
        }