I’ve made a custom uitableviewcell . The cell consist out of labels and a UIButton. Everything was working fine until I found out that there is a small problem with the reusable cell in combination with adding an event to an uibutton.
So the first time the cell works great when I click the uibutton. But the moment I scroll it starts giving me the wrong detail info. If I comment out the reusable cell part (and let it make a new cell everytime) it just works fine with no problems. So my assumptions is that the event ‘hangs on’ into cell with the old info.
I add the event like this:
myButton.TouchDown += delegate{
//some code here
}
Obviously I cannot unregister it like this right?
What is the easiest way to overcome this particular problem in monotouch?
OK. I’ve been trying a lot of stuff to solve this but ChrisNTR came with the right solution to my particular problem. I will show his example snippet here:
In short you call button.AddTarget() and you pass the corresponding values to the button. one of these values is the selector which you defined as ‘buttonEventHere’ (can be any name you want it to me my sure that the [export(“MySelector”)] has the right name). Make sure you pass the indexPath.Row to the button.Tag. You will use that index to know which button was pressed and do your action accordingly.
Hope this helps if you was stuck as i was.