Last active
          August 29, 2015 14:10 
        
      - 
      
 - 
        
Save hjerpbakk/622e5855f95189e13d77 to your computer and use it in GitHub Desktop.  
    Using a TaskCompletionSource to enable async and await together with UIAlertController. From: http://www.hjerpbakk.com/blog/2014/11/23/from-uialertview-to-uialertcontroller-using-xamarin-and-async-await
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | public static class CustomerFeelingSheet { | |
| public static Task<CustomerFeeling> ShowRatingDialogAsync(UIViewController parent) { | |
| var taskCompletionSource = new TaskCompletionSource<CustomerFeeling>(); | |
| var alert = UIAlertController.Create("howDoYouFeel".T(), null, UIAlertControllerStyle.ActionSheet); | |
| alert.AddAction(UIAlertAction.Create("likeIt".T(), UIAlertActionStyle.Default, | |
| a => taskCompletionSource.SetResult(CustomerFeeling.LikeIt))); | |
| alert.AddAction(UIAlertAction.Create("couldBeBetter".T(), UIAlertActionStyle.Default, | |
| a => taskCompletionSource.SetResult(CustomerFeeling.CouldBeBetter))); | |
| alert.AddAction(UIAlertAction.Create("cancel".T(), UIAlertActionStyle.Cancel, | |
| a => taskCompletionSource.SetResult(CustomerFeeling.DontCare))); | |
| parent.PresentViewController(alert, true, null); | |
| return taskCompletionSource.Task; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment