Something else to keep in mind that has bitten me in the past:

If you present a confirmation dialog, remember that while it's displayed if 
there's any chance the table could refresh (and thus re-load that cell with a 
different set of parameters) the wrong "cell" will get acted on instead. This 
was happening to me because the device was getting TCP communications generated 
from elsewhere that would alter its list of cells - sometimes removing one, 
which might cause the cell to be re-populated with different data.

Because only one cell could ever have an active confirmation dialog at any 
given time, I loaded the parameters of that cell into static properties, and 
acted on the static properties once the user confirmed.

Dino

-----Original Message-----
From: Steve Keane [mailto:[email protected]] 
Sent: Monday, September 12, 2011 8:35 AM
To: Dean Cleaver
Subject: RE: [MonoTouch] How to add event handler for custom UITableCell button 
(without it being called many times)? - Email found in subject

Thanks. That makes good sense, I will look into that.

Thanks for the help!


Steve

-----Original Message-----
From: Dean Cleaver [mailto:[email protected]] 
Sent: 12 September 2011 13:56
To: Dean Cleaver; Steve Keane; [email protected]
Subject: RE: [MonoTouch] How to add event handler for custom UITableCell button 
(without it being called many times)? - Email found in subject

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

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.901 / Virus Database: 271.1.1/3891 - Release Date: 09/11/11 
19:38:00
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to