맞춤 헤더로 TableView를 만들고 있습니다. 사용자 정의 헤더에는 1 ImageView, 2 UILabel 및 1 UIButton이 있습니다. TouchUpInSide 이벤트를 UIButton에 설정하면 실행되지 않습니다.버튼 클릭 내부에서 TableView 헤더가 무시됩니다.
나는 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을 확장합니다.
어떤 도움을 이해할 수있을 것이다 ..
나는 구조체이기 때문에 상위 코드에서 표시하지 않는 것이 좋습니다. – Ironman
내가 코드에서 보았 듯이 organizationInrowButton에 대해 userInteractionEnabled를 설정하거나 backgroundImage를 – Van
으로 설정하여 backgroundImage.UserInteractionEnabled = true로 설정해야합니다. –