Skip to content

Instantly share code, notes, and snippets.

@tomgilder
Created November 22, 2013 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomgilder/7601311 to your computer and use it in GitHub Desktop.
Save tomgilder/7601311 to your computer and use it in GitHub Desktop.
BufferTouchViewPresenter
using System;
using System.Collections.Generic;
using Cirrious.CrossCore.Exceptions;
using Cirrious.MvvmCross.Touch.Views;
using Cirrious.MvvmCross.Touch.Views.Presenters;
using MonoTouch.UIKit;
namespace ScriptTimer.iOS
{
public class BufferTouchViewPresenter : MvxTouchViewPresenter
{
private bool isLaunching = true;
private readonly List<UIViewController> bufferedViewControllers = new List<UIViewController>();
public BufferTouchViewPresenter(UIApplicationDelegate applicationDelegate, UIWindow window) : base(applicationDelegate, window)
{
UIApplication.Notifications.ObserveDidFinishLaunching(HandleFinishedLaunching);
}
void HandleFinishedLaunching(object sender, UIApplicationLaunchEventArgs e)
{
this.isLaunching = false;
SetNavigationController();
}
void SetNavigationController()
{
var navController = new UINavigationController();
navController.SetViewControllers(this.bufferedViewControllers.ToArray(), false);
this.MasterNavigationController = navController;
this.OnMasterNavigationControllerCreated();
this.SetWindowRootViewController(navController);
}
public override void Show(IMvxTouchView view)
{
UIViewController uIViewController = view as UIViewController;
if (uIViewController == null)
{
throw new MvxException("Passed in IMvxTouchView is not a UIViewController");
}
if (this.isLaunching)
{
this.bufferedViewControllers.Insert(0, uIViewController);
}
else
{
this.MasterNavigationController.PushViewController(uIViewController, true);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment