gpt4 book ai didi

c# - 标签不显示文本 - Xamarin IOS

转载 作者:行者123 更新时间:2023-11-28 18:29:47 24 4
gpt4 key购买 nike

我正在做一个倒计时,应该在计数中显示一个标签,但我的 View Controller 上的标签 (lblMostrador) 不显示文本。代码是正确的,因为输出框正确显示了计数。标签工作是否有特殊配置或其他?

部分类 EsquerdaViewController : UIViewController {

    private System.Timers.Timer aTimer;
private DateTime tempo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 1, 0);
private DateTime tempo2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 1);


public EsquerdaViewController (IntPtr handle) : base (handle)
{
}

public override void ViewDidLoad()
{
base.ViewDidLoad ();
Console.WriteLine ("Testando...");

btnVoltar.TouchUpInside += (sebder, e) =>
{
NavigationController.PopViewController(true);
};


btnIniciar.TouchUpInside += (sender, e) =>
{
aTimer = new System.Timers.Timer(1000);

aTimer.Elapsed += OnTimedEvent;

aTimer.AutoReset = true;

aTimer.Enabled = true;

};


}

private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
System.TimeSpan diff1 = tempo.Subtract(tempo2);

if (diff1.Minutes == 0 && diff1.Seconds == 0)
aTimer.Stop();

DateTime tempoNovo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, diff1.Minutes, diff1.Seconds);
tempo = tempoNovo;
Console.WriteLine (String.Format("{0:00}:{1:00}", diff1.Minutes, diff1.Seconds));
lblMostrador.Text = String.Format ("{0:00}:{1:00}", diff1.Minutes, diff1.Seconds);
}
}

最佳答案

更新 UI 对象时,需要确保在 UI 线程上执行:

InvokeOnMainThread ( () => {
lblMostrador.Text = String.Format ("{0:00}:{1:00}", diff1.Minutes, diff1.Seconds);
});

关于c# - 标签不显示文本 - Xamarin IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35733688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com