自定义单元格中未触发Xamarin Forms UIButton事件

sigwle7e  于 2023-04-18  发布在  其他
关注(0)|答案(1)|浏览(114)

我不知道这是否是最好的方法,但是在我们的应用程序中,我们有一个CustomCell类来在表视图中显示数据。
直到上周,它还在正常工作。
当前未触发按钮TouchUpInside事件。
新的iOS版本?
有什么想法吗?
下面是一个例子:

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");
        }
    }

}
k97glaaz

k97glaaz1#

Coskun通过在CustomCell中执行以下操作来解决此问题:

this.ContentView.UserInteractionEnabled = false;

相关问题