iOS TableView button is being called multiple times
<p>I have a TableView with a custom UITableViewCell. In each cell I have multiple buttons, when any of the buttons is click after scrolling down and up it calls itself the many times I scroll down and up. </p>

<p>I have read and research for a solution and I haven't found a solution. </p>

<p>I know the problem is the cell are being reuse so that's why the buttons are being call multiple times but I can't find a way to prevent it.</p>

<p>I added console write line statements through the code and the else part in MoveToWindow is never call. Could that be the reason why? </p>

<p>Research material for solution:</p>

<p><a href="https://forums.xamarin.com/discussion/36258/my-code-is-calling-twice-the-btndelete-method-in-uitableview" rel="nofollow noreferrer">my code is calling twice the btndelete method in uitableview</a></p>

<p><a href="https://stackoverflow.com/questions/25498047/uibutton-click-event-getting-called-multiple-times-inside-custom-uitableviewcell">UIButton click event getting called multiple times inside custom UITableViewCell</a></p>

<p>My Code:</p>

<pre><code>namespace Class.iOS
{
    public partial class CustomCell : UITableViewCell
    {
        public static readonly NSString Key = new NSString ("CustomCell");
        public static readonly UINib Nib;
        public int Row { get; set; }
        public event EventHandler LikeButtonPressed;

        private void OnLikeButtonPressed()
        {
            if (LikeButtonPressed != null)
            {
                LikeButtonPressed(this, EventArgs.Empty);
            }
        }

        public override void MovedToWindow()
        {
            if (Window != null)
            {
                btnAdd.TouchUpInside += HandleLikeButtonPressed;
            }
            else
            {
                btnAdd.TouchUpInside -= HandleLikeButtonPressed;
            }
        }

        private void HandleLikeButtonPressed(object sender, EventArgs e)
        {
            OnLikeButtonPressed();
        }

        static CustomCell ()
        {
            Nib = UINib.FromName ("CustomCell", NSBundle.MainBundle);
        }

        public CustomCell ()
        {           
        }

        public CustomCell (IntPtr handle) : base (handle)
        {           
        }

        public void UpdateCell (string Name, int number)
        {
            // some code
        }

        public class TableSource : UITableViewSource
        {           
            public override nint RowsInSection (UITableView tableview, nint section)
            {
                return 8;
            }

            private void HandleLikeButtonPressed(object sender, EventArgs e)
            {
                var cell = (CustomCell)sender;
                var row = cell.Row;

                switch (row) 
                {
                case 0:
                    cell.label.Text = ""
                    break;
                case 1:
                    cell.label.Text = ""
                    break;
                }
            }
            public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
            {
                var cell = tableView.DequeueReusableCell (CustomCell.Key) as CustomCell;
                cell.Row = indexPath.Row;

                if (cell == null) 
                {
                    cell = new CustomCell ();
                    var views = NSBundle.MainBundle.LoadNib("CustomCell", cell, null);
                    cell.LikeButtonPressed += HandleLikeButtonPressed;
                    cell = Runtime.GetNSObject( views.ValueAt(0) ) as CustomCell;

                }

                cell.UpdateCell 
                (
                    // some code
                );

                return cell;
            }
        }
    }
}
</code></pre>