Skip to content

Instantly share code, notes, and snippets.

@nicwise
Created October 17, 2013 15:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicwise/7026601 to your computer and use it in GitHub Desktop.
Save nicwise/7026601 to your computer and use it in GitHub Desktop.
using async/await and a task completion source to work with NavigationController etc.
//start with DoAdd, which comes off a button push.
// it does pop up one screen, then another one, which is not ideal,
// but it wouldn't be hard to adapt.
async void DoAdd ()
{
var camera = await PickCameraForLoad ();
if (camera != null)
{
var newFilmLoad = new FilmLoad () { Id = -1, Loaded = DateTime.Now, CameraId = camera.Id };
DoEdit (newFilmLoad, true);
}
}
Task<Camera> PickCameraForLoad ()
{
var tcs = new TaskCompletionSource<Camera> ();
var dvc = new CameraListDialogViewController ();
dvc.OnPickedCamera += (c) => dvc.DismissViewController (true, () => tcs.SetResult (c));
dvc.OnCancel += () => dvc.DismissViewController (true, () => tcs.SetResult (null));
PresentViewController (new UINavigationController (dvc), true, null);
return tcs.Task;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment