Created
November 22, 2013 15:03
-
-
Save tomgilder/7601311 to your computer and use it in GitHub Desktop.
BufferTouchViewPresenter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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