Created
October 17, 2013 15:07
-
-
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.
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
//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