private void DisplayUserResponse(NSArray result) { var answer = "No answer"; if (result != null) { if (result.Count > 0) { answer = result.GetItem <NSObject>(0).ToString(); } } LabelAnswer.SetText(answer); ComplicationHelper.Answer = answer; ComplicationHelper.UpdateComplications(); }
private Timer timer; #endregion #region Constructor protected InterfaceController(IntPtr handle) : base(handle) { // Note: this .ctor should not contain any initialization logic. } #endregion #region Lifecycle public override void Awake(NSObject context) { base.Awake(context); SetTitle("Hello, watch!"); ConfigureTimer(); DisplayInfo("Awake"); } public override void WillActivate() { UpdateTimer(); DisplayInfo("WillActivate"); } public override void DidDeactivate() { UpdateTimer(false); DisplayInfo("DidDeactivate"); } public override void DidAppear() { DisplayInfo("DidAppear"); } public override void WillDisappear() { DisplayInfo("WillDisappear"); } #endregion #region Timer private void ConfigureTimer() { if (timer == null) { timer = new Timer(); timer.Elapsed += (sender, e) => { DisplayCurrentTime(); }; timer.Interval = 1000; } } private void DisplayCurrentTime() { var time = String.Format("{0:HH:mm:ss}", DateTime.Now); LabelTime.SetText(time); } private void UpdateTimer(bool start = true) { if (start) { DisplayCurrentTime(); timer.Start(); } else { timer.Stop(); } } #endregion #region Text input partial void ButtonInput_Activated() { var colors = new string[] { "Red", "Green", "Blue", "Orange", "Purple" }; PresentTextInputController(colors, WKTextInputMode.AllowEmoji, DisplayUserResponse); } private void DisplayUserResponse(NSArray result) { var answer = "No answer"; if (result != null) { if (result.Count > 0) { answer = result.GetItem<NSObject>(0).ToString(); } } LabelAnswer.SetText(answer); ComplicationHelper.Answer = answer; ComplicationHelper.UpdateComplications(); } #endregion #region Menu partial void NewYorkItem_Tapped() { DisplayCityGeolocationController(City.NewYork); }