Monotouch.Dialog - 点击了哪个元素

Ian*_*ink 7 iphone xamarin.ios monotouch.dialog

我有一个客户列表,我用它来创建像这样的元素:

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

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

如何设置Tapped Delegate包含将标记客户的信息

Wae*_*her 13

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

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)); };
}
Run Code Online (Sandbox Code Playgroud)

但这不是MonoTouch.Dialog的限制.是一篇关于一般问题的文章.