Search code examples
c#iosxamarinipados

Xamarin Forms UIButton event is not triggered in custom cell


I don't know if this is the best way but, in our application, we have a CustomCell class to show datas in a table view.

Until the last week, it was working properly.

Currently the button TouchUpInside event is not triggered.

Maybe the new iOS version ?

Any idea, please?

Here is the class :

public class CustomCell : UITableViewCell
{
    public static readonly string ID = "CustomCell";
    public UILabel FullName;
    public UILabel BirthDate;
    public UILabel Phone;
    public UILabel Observations;
    public UILabel Gender;
    public int PatientID;
    public UIButton Modify;
            
    public CustomCell ()
    {
        Gender = new UILabel (new CGRect (15, 0, 85, 35)) {
            Font = UIFont.FromName ("Trebuchet MS", 14f)
        };
        

        FullName = new UILabel (new CGRect (100, 0, 200, 35)) {
            Font = UIFont.FromName ("Trebuchet MS", 14f)
        };

        BirthDate = new UILabel (new CGRect (310, 0, 100, 35)) {
            Font = UIFont.FromName ("Trebuchet MS", 14f)
        };
        Phone = new UILabel (new CGRect (435, 0, 110, 35)) {
            Font = UIFont.FromName ("Trebuchet MS", 14f)
        };

        Observations = new UILabel (new CGRect (550, 0, 450, 35)) {
            Font = UIFont.FromName ("Trebuchet MS", 13f)
        };

        Modify = new UIButton (new CGRect (270, 5, 28, 28)){ };

        var img = UIImage.FromFile("edit.png");
    
        Modify.SetBackgroundImage (img, UIControlState.Normal);
        Modify.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin;
        Modify.TouchUpInside += ModifyTouchUpInside;

        AddSubview (Gender);
        AddSubview (FullName);
        AddSubview (BirthDate);
        AddSubview (Phone);
        AddSubview (Observations);

        if(Tools.ShowModifyIcon)
          AddSubview (Modify);
        this.ContentView.UserInteractionEnabled = true;
    }


    
    void ModifyTouchUpInside (object sender, EventArgs e)
    {
        try {

            Tools.PatientsPage.ShowPopup (this.PatientID);

        } catch (Exception ex) {
            UserMethods.ParseError (ex, "Err139");
        }
    }

}

Solution

  • Coskun managed to fix this problem by simply doing below in the CustomCell:

    this.ContentView.UserInteractionEnabled = false;