示例#1
0
        private static void DisposeViewController(UIViewController viewController)
        {
            var viewControllerView = viewController as IViewControllerView;

            if (viewControllerView == null || viewControllerView.Mediator.IsViewLoaded)
            {
                viewController.View.ClearBindingsRecursively(true, true);
                viewController.View.DisposeEx();
                viewController.EditButtonItem.ClearBindings(true, true);
                viewController.EditButtonItem.DisposeEx();
                viewController.ToolbarItems.ClearBindings(true, true);
                viewController.ToolbarItems.DisposeEx();
                UINavigationItem navigationItem = viewController.NavigationItem;
                if (navigationItem != null)
                {
                    navigationItem.LeftBarButtonItem.ClearBindings(true, true);
                    navigationItem.LeftBarButtonItem.DisposeEx();
                    navigationItem.LeftBarButtonItems.ClearBindings(true, true);
                    navigationItem.LeftBarButtonItems.DisposeEx();
                    navigationItem.RightBarButtonItem.ClearBindings(true, true);
                    navigationItem.RightBarButtonItem.DisposeEx();
                    navigationItem.RightBarButtonItems.ClearBindings(true, true);
                    navigationItem.RightBarButtonItems.DisposeEx();
                    navigationItem.ClearBindings(true, true);
                    navigationItem.DisposeEx();
                }

                var dialogViewController = viewController as DialogViewController;
                if (dialogViewController != null)
                {
                    dialogViewController.Root.ClearBindingsRecursively(true, true);
                    dialogViewController.Root.DisposeEx();
                }
            }

            var tabBarController = viewController as UITabBarController;

            if (tabBarController == null)
            {
                var splitViewController = viewController as UISplitViewController;
                if (splitViewController != null)
                {
                    splitViewController.ViewControllers.ClearBindings(true, true);
                    splitViewController.ViewControllers.DisposeEx();
                }
            }
            else
            {
                tabBarController.ViewControllers.ClearBindings(true, true);
                tabBarController.ViewControllers.DisposeEx();
            }

            viewController.ChildViewControllers.ClearBindings(true, true);
            viewController.ChildViewControllers.DisposeEx();
            viewController.Dispose();
        }
        private void TryDispose()
        {
            var viewController = ViewController;

            if (viewController == null)
            {
                return;
            }
            if (!_canDispose || !_isDisposeCalled)
            {
                return;
            }
            Raise(DisposeHandler);

            if (_isViewLoaded)
            {
                viewController.View.ClearBindingsRecursively(true, true);
                viewController.View.DisposeEx();
                viewController.EditButtonItem.ClearBindings(true, true);
                viewController.EditButtonItem.DisposeEx();
                viewController.ToolbarItems.ClearBindings(true, true);
                viewController.ToolbarItems.DisposeEx();
                UINavigationItem navigationItem = viewController.NavigationItem;
                if (navigationItem != null)
                {
                    navigationItem.LeftBarButtonItem.ClearBindings(true, true);
                    navigationItem.LeftBarButtonItem.DisposeEx();
                    navigationItem.LeftBarButtonItems.ClearBindings(true, true);
                    navigationItem.LeftBarButtonItems.DisposeEx();
                    navigationItem.RightBarButtonItem.ClearBindings(true, true);
                    navigationItem.RightBarButtonItem.DisposeEx();
                    navigationItem.RightBarButtonItems.ClearBindings(true, true);
                    navigationItem.RightBarButtonItems.DisposeEx();
                    navigationItem.ClearBindings(true, true);
                    navigationItem.DisposeEx();
                }

                var dialogViewController = viewController as DialogViewController;
                if (dialogViewController != null)
                {
                    dialogViewController.Root.ClearBindingsRecursively(true, true);
                    dialogViewController.Root.DisposeEx();
                }
            }

            var tabBarController = ViewController as UITabBarController;

            if (tabBarController == null)
            {
                var splitViewController = ViewController as UISplitViewController;
                if (splitViewController != null)
                {
                    splitViewController.ViewControllers.ClearBindings(true, true);
                    splitViewController.ViewControllers.DisposeEx();
                }
            }
            else
            {
                tabBarController.ViewControllers.ClearBindings(true, true);
                tabBarController.ViewControllers.DisposeEx();
            }

            viewController.ChildViewControllers.ClearBindings(true, true);
            viewController.ChildViewControllers.DisposeEx();
            viewController.ClearBindings(true, true);
            viewController.DisposeEx();
            ViewDidLoadHandler           = null;
            ViewWillAppearHandler        = null;
            ViewDidAppearHandler         = null;
            ViewDidDisappearHandler      = null;
            ViewWillDisappearHandler     = null;
            DecodeRestorableStateHandler = null;
            EncodeRestorableStateHandler = null;
            DisposeHandler  = null;
            _viewController = null;
        }