gpt4 book ai didi

iphone - Monotouch.Dialog - 哪个元素被点击

转载 作者:行者123 更新时间:2023-12-03 18:38:19 25 4
gpt4 key购买 nike

我有一个客户列表,我用它来创建如下元素:

Foreach(Customer c in Customers)
{
//Make the StyledStringElement
//Set the Tapped to action a touch
element.Tapped += () => { Push (new SomeController (c.ClientId)); };
}

问题是,当点击该元素时,它会将最后一个客户发送到 SomeController()。

如何设置带有识别客户信息的点击委托(delegate)?

最佳答案

您需要将客户保留为循环中的局部变量:

foreach(Customer c in Customers)
{
//Make the StyledStringElement
//Set the Tapped to action a touch
var currentCustomer = c;
element.Tapped += () => { Push (new SomeController (currentCustomer.ClientId)); };
}

但这不是 MonoTouch.Dialog 的限制。 Here's关于一般问题的文章。

关于iphone - Monotouch.Dialog - 哪个元素被点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5700406/

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