我正在使用自定义标头进行tableview。在自定义标题中,我有1个ImageView,2个Uilabel和1个Uibutton。当我在Uibutton上设置Touchupinside事件时,它不会发射。
我在SO和Google上看到许多帖子,但没有任何帮助。
我尝试过的东西:
1)。Swift-自定义表视图不执行单击UIBUTTON
2)。uibutton in uitableview tableheaderview不响应触摸
3)。uibleview标头中的uibutton忽略了大多数触摸
这是我的自定义标题代码。
代码:
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。
任何帮助将不胜感激。
uiimageView的用户互动默认情况下是禁用的,并且您将按钮添加到图像视图,将UserInterActionEnabled设置为true for UiimageView。