I have a list of Customers which I use to create Elements like this:
Foreach(Customer c in Customers)
{
//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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With