Monotouch.Dialog - Which item was used

I have a list of clients that I use to create these items:

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 an element is used, it sends the last client to SomeController ().

How to set up a Tapped Delegate with information that will identify the client ?

+7
source share
1 answer

You need to save the client as a local variable in a 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 is an article about a common problem.

+13
source

All Articles