Sorry - not the constructor of the cell as that's only called once. I have 
properties on the cell that are set during GetCell and the values for that 
might have been passed in to the constructor of the DataSource.

Dino

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Dean Cleaver
Sent: Monday, September 12, 2011 7:50 AM
To: stevek; [email protected]
Subject: Re: [MonoTouch] How to add event handler for custom UITableCell button 
(without it being called many times)?

Personally, I pass in the parameters/object it needs to act on to the 
constructor of the custom cell, and have the event code in the cell perform the 
required action.

Dino

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of stevek
Sent: Monday, September 12, 2011 7:04 AM
To: [email protected]
Subject: [MonoTouch] How to add event handler for custom UITableCell button 
(without it being called many times)?

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
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to