开发者

Monotouch.Dialog - Which Element was Tapped

I have a list of Customers which I use to create Elements like this:

Foreach(Customer c in Customers)
{
 开发者_如何学JAVA   //Make the StyledStringElement
    //Set the Tapped to action a touch
    element.Tapped += () => {  Push (new SomeController (c.ClientId)); };
}

The problem is that when the element is tapped it sends the last customer to SomeController().

How can I set the Tapped Delegate with information that will id the customer?


You need to keep the customer as local variable in the loop:

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)); };
}

But this is not a limitation with MonoTouch.Dialog. Here's an article about the general problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜