private void ViewModel_OnPresenterNeedsToNavigate(object sender, BaseViewModel e)
        {
            UIViewController viewController = ViewModelToViewConverter.Convert(e);

            MyNavigationController.ShowViewController(viewController, null);
            _liveViews.Add(new Tuple <BaseViewModel, UIViewController>(e, viewController));
        }
        private void ListOfViewModelsPresenter_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_viewModels != sender)
            {
                return;
            }

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                // If simply adding one new one, animate with push
                if (e.NewItems.Count == 1 && e.NewStartingIndex == _liveViews.Count)
                {
                    UIViewController viewController = ViewModelToViewConverter.Convert(e.NewItems[0] as BaseViewModel);
                    base.ShowViewController(viewController, null);
                    _liveViews.Add(new Tuple <BaseViewModel, UIViewController>(e.NewItems[0] as BaseViewModel, viewController));
                }
                else
                {
                    Add(e.NewStartingIndex, e.NewItems.OfType <BaseViewModel>().ToArray());
                }

                break;

            case NotifyCollectionChangedAction.Remove:

                // If removing the last (and we have multiple), simply go back
                if (e.OldItems.Count == 1 && e.OldStartingIndex == _liveViews.Count - 1 && base.ViewControllers.Length > 1)
                {
                    base.PopViewController(true);
                    _liveViews.RemoveAt(e.OldStartingIndex);
                }
                else
                {
                    Remove(e.OldStartingIndex, e.OldItems.Count);
                }
                break;

            case NotifyCollectionChangedAction.Move:
                List <UIViewController> final = new List <UIViewController>(base.ViewControllers);
                MoveRange(final, e.OldStartingIndex, e.NewStartingIndex, e.NewItems.Count);
                base.ViewControllers = final.ToArray();
                MoveRange(_liveViews, e.OldStartingIndex, e.NewStartingIndex, e.NewItems.Count);
                break;

            case NotifyCollectionChangedAction.Replace:
                Remove(e.OldStartingIndex, e.OldItems.Count);
                Add(e.NewStartingIndex, e.NewItems.OfType <BaseViewModel>().ToArray());
                break;

            case NotifyCollectionChangedAction.Reset:
                Reset();
                break;
            }
        }
        private void Add(int index, BaseViewModel[] items)
        {
            var viewControllers = base.ViewControllers.ToList();

            foreach (var item in items)
            {
                UIViewController viewController = ViewModelToViewConverter.Convert(item);
                viewControllers.Insert(index, viewController);
                _liveViews.Insert(index, new Tuple <BaseViewModel, UIViewController>(item, viewController));

                index++;
            }

            base.ViewControllers = viewControllers.ToArray();
        }
        private void Reset()
        {
            Remove(0, _liveViews.Count);

            List <UIViewController> newControllers = new List <UIViewController>();

            if (_viewModels != null)
            {
                foreach (var model in _viewModels)
                {
                    var view = ViewModelToViewConverter.Convert(model);
                    newControllers.Add(view);
                    _liveViews.Add(new Tuple <BaseViewModel, UIViewController>(model, view));
                }
            }

            base.ViewControllers = newControllers.ToArray();
        }
        private void ViewModel_OnPresenterNeedsToReplaceWithinBackStack(object sender, Tuple <BaseViewModel, BaseViewModel> e)
        {
            var matchingView = FindViewMatchingViewModel(e.Item1);

            if (matchingView != null)
            {
                var updatedControllers = MyNavigationController.ViewControllers.ToArray();
                int index = updatedControllers.ToList().IndexOf(matchingView);

                UIViewController viewController = ViewModelToViewConverter.Convert(e.Item2);
                updatedControllers[index] = viewController;

                MyNavigationController.ViewControllers = updatedControllers;

                _liveViews.RemoveWhere(i => i.Item1 == e.Item1);
                _liveViews.Add(new Tuple <BaseViewModel, UIViewController>(e.Item2, viewController));
            }
        }