Skip to content

Instantly share code, notes, and snippets.

@yehorhromadskyi
Created July 1, 2019 11:15
Show Gist options
  • Save yehorhromadskyi/7201f7eb949fb7cf77a628586fd0137b to your computer and use it in GitHub Desktop.
Save yehorhromadskyi/7201f7eb949fb7cf77a628586fd0137b to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using UIKit;
namespace interview_questions_ios
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var button = new UIButton(UIButtonType.System)
{
Frame = new CoreGraphics.CGRect(100, 10, 200, 100)
};
button.SetTitle("Load data", UIControlState.Normal);
button.TouchUpInside += (sender, e) =>
{
var data = LoadDataAsync().Result;
button.SetTitle(data, UIControlState.Normal);
};
var button2 = new UIButton(UIButtonType.System)
{
Frame = new CoreGraphics.CGRect(100, 110, 200, 100)
};
button2.SetTitle("Load data 2", UIControlState.Normal);
button2.TouchUpInside += async (sender, e) =>
{
var data = await LoadDataAsync().ConfigureAwait(false);
button2.SetTitle(data, UIControlState.Normal);
};
var button3 = new UIButton(UIButtonType.System)
{
Frame = new CoreGraphics.CGRect(100, 210, 200, 100)
};
button3.SetTitle("Load data 3", UIControlState.Normal);
button3.TouchUpInside += async (sender, e) =>
{
var data1 = await LoadDataAsync();
var data2 = await LoadDataAsync();
var data3 = await LoadDataAsync();
var data = data1 + data2 + data3;
button3.SetTitle(data, UIControlState.Normal);
};
View.AddSubview(button);
View.AddSubview(button2);
View.AddSubview(button3);
}
async Task<string> LoadDataAsync()
{
await Task.Delay(1000);
return "42";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment