I am having trouble trying to and an event handler for a delete button that
is on a custom UITableCell
Currently the delegate seems to get called several times for each click on
the delete button. I am using an anonymous method as I need the indexPath to
work out which message to delete.
Can anyone suggest a way of ensuring the event is only called once or an
alternative method so I can use the indexPath to determine which message to
delete without using an delegate in the GetCell method?
The code I currently have is:
>>>>>>>>>>>>>>>>
public override UITableViewCell GetCell (UITableView tableView,
NSIndexPath
indexPath)
{
SprayCell cell = tableView.DequeueReusableCell (kCellIdentifier) as
SprayCell;
if (cell == null) {
cell = new SprayCell();
var views =
NSBundle.MainBundle.LoadNib("SprayCell",cell,null);
cell = Runtime.GetNSObject(views.ValueAt(0)) as
SprayCell;
//If I do this here it only ever tries to
delete the 1st few messages
/*
cell.DeleteButton.TouchUpInside += delegate {
Util.Debug("cell.DeleteButton.TouchUpInside() -
DELETE MsgID" +
_list2[indexPath.Row].MessageID);
};
*/
};
}
cell.Text = _list2[indexPath.Row].Body;
cell.Date1 = "received " +
_list2[indexPath.Row].TimeStamp.ToShortTimeString() + " " +
_list2[indexPath.Row].TimeStamp.ToShortDateString() ;
cell.DeleteButton.TouchUpInside -= delegate {}; //If I
don't have this we
get lots of different events firing when we have lots of items in the list
cell.DeleteButton.TouchUpInside += delegate
{cell.DeleteButton.TouchUpInside() - DELETE MsgID" +
_list2[indexPath.Row].MessageID)}; //Gets called multiple times randomly and
regularly at the top/bottom of the list
return cell;
}
<<<<<<<<<<<<<<<<<
Many Thanks
SK
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/How-to-add-event-handler-for-custom-UITableCell-button-without-it-being-called-many-times-tp3807201p3807201.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch