按钮单击里面的TableView Header在iOS中被忽略

时间:2017-12-08 10:21:15

标签: ios uitableview xamarin uibutton dialogviewcontroller

我正在使用自定义标头创建TableView。在自定义标题中,我有1个ImageView,2个UILabel和1个UIButton。当我在UIButton上设置TouchUpInSide事件时,它不会触发。

我在SO和google上看到很多帖子,但没有任何东西可以帮助我。

这里我尝试过:

1)。 Swift - Custom TableView Not Executing Click on UIButton

2)。 UIButton in UITableView tableHeaderView not responding to touches

3)。 UIButton in a UITableView header ignores most touches

这是我的自定义标题的代码。

代码:

public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TableView.Frame = new RectangleF((float)TableView.Frame.Left, 130, (float)TableView.Frame.Width, (float)(View.Frame.Size.Height - 130));
            headerView = new UIView();
            headerView.Frame = new CoreGraphics.CGRect(0, 0, TableView.Frame.Width, 140);

            UIImageView backgroundImage = new UIImageView();
            backgroundImage.Image = UIImage.FromFile("drawerbg");
            backgroundImage.Frame = new CoreGraphics.CGRect(0, 0, TableView.Frame.Width, 140);
            headerView.AddSubview(backgroundImage);

            profileImage = new UIImageView();
            profileImage.Frame = new CoreGraphics.CGRect(10, 10, 70, 70);
            profileImage.Layer.CornerRadius = 35;
            profileImage.ClipsToBounds = true;
            profileImage.Image = UIImage.FromBundle("default_user");
            backgroundImage.AddSubview(profileImage);

            userName = new UILabel();
            userName.Frame = new CoreGraphics.CGRect(10, 90, TableView.Frame.Width - 20, 20);
            userName.Font = GargiFontAndSize.B14();
            userName.TextColor = UIColor.White;
            backgroundImage.AddSubview(userName);

            userOrganization = new UILabel();
            userOrganization.Frame = new CoreGraphics.CGRect(10, 110, TableView.Frame.Width - 50, 20);
            userOrganization.Font = GargiFontAndSize.B14();
            userOrganization.TextColor = UIColor.White;
            userOrganization.Text = "Organizaton";
            backgroundImage.AddSubview(userOrganization);

            organizationArrowButton = new UIButton();
            organizationArrowButton.Frame = new CoreGraphics.CGRect(260, 110, 20, 20);
            organizationArrowButton.SetImage(UIImage.FromBundle("sort_down"), UIControlState.Normal);
            organizationArrowButton.UserInteractionEnabled = true;
            organizationArrowButton.ClipsToBounds = false;
            backgroundImage.AddSubview(organizationArrowButton);
            organizationArrowButton.BringSubviewToFront(headerView);


            TableView.SectionHeaderHeight = 0;
            TableView.SectionFooterHeight = 0;


            var gradient = new CAGradientLayer();
            gradient.Frame = headerView.Frame;
            gradient.Colors = new CoreGraphics.CGColor[] { GargiColor.PrimaryColor().CGColor, GargiColor.SecondaryColor().CGColor };
            headerView.Layer.InsertSublayer(gradient, 0);

            TableView.TableHeaderView = headerView;

}

我的viewController还有一个扩展DialogViewController。

任何帮助都会得到赞赏..

1 个答案:

答案 0 :(得分:0)

默认情况下,UIImageView的userInteraction被禁用,您正在向图像视图添加按钮,为UIImageView将userInteractionEnabled设置为true。