jjzjj

ios - 在 iOS 中忽略 TableView 标题内的按钮单击

coder 2024-01-28 原文

我正在制作带有自定义页眉的 TableView。在自定义 header 中,我有 1 个 ImageView、2 个 UILabel 和 1 个 UIButton。当我在 UIButton 上设置 TouchUpInSide 事件时,它不会触发。

我在 SO 和谷歌上看到很多帖子,但没有任何帮助。

这里是我尝试过的:

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

这是我的自定义 header 代码。

代码:

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 的 userInteraction 默认是禁用的,如果你要添加按钮到 ImageView ,将 UIImageView 的 userInteractionEnabled 设置为 true。

关于ios - 在 iOS 中忽略 TableView 标题内的按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47712258/

有关ios - 在 iOS 中忽略 TableView 标题内的按钮单击的更多相关文章

  1. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  2. ruby-on-rails - 使用 Rmagick 或 ImageMagick 在背景上放置标题 - 2

    我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植

  3. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  4. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  5. c - mkmf 在编译 C 扩展时忽略子文件夹中的文件 - 2

    我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。

  6. ruby-on-rails - 从应用程序中自定义文件夹内的命名空间自动加载 - 2

    我们目前正在为ROR3.2开发自定义cms引擎。在这个过程中,我们希望成为我们的rails应用程序中的一等公民的几个类类型起源,这意味着它们应该驻留在应用程序的app文件夹下,它是插件。目前我们有以下类型:数据源数据类型查看我在app文件夹下创建了多个目录来保存这些:应用/数据源应用/数据类型应用/View更多类型将随之而来,我有点担心应用程序文件夹被这么多目录污染。因此,我想将它们移动到一个子目录/模块中,该子目录/模块包含cms定义的所有类型。所有类都应位于MyCms命名空间内,目录布局应如下所示:应用程序/my_cms/data_source应用程序/my_cms/data_ty

  7. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  8. Ruby - 如何在读取文件时跳过/忽略特定行? - 2

    在读取/解析文件(使用Ruby)时忽略某些行的最佳方法是什么?我正在尝试仅解析Cucumber.feature文件中的场景,并希望跳过不以Scenario/Given/When/Then/And/But开头的行。下面的代码有效,但它很荒谬,所以我正在寻找一个聪明的解决方案:)File.open(file).each_linedo|line|line.chomp!nextifline.empty?nextifline.include?"#"nextifline.include?"Feature"nextifline.include?"Inorder"nextifline.include?

  9. sql - 查询忽略时间戳日期的时间范围 - 2

    我正在尝试查询我的Rails数据库(Postgres)中的购买表,我想查询时间范围。例如,我想知道在所有日期的下午2点到3点之间进行了多少次购买。此表中有一个created_at列,但我不知道如何在不搜索特定日期的情况下完成此操作。我试过:Purchases.where("created_atBETWEEN?and?",Time.now-1.hour,Time.now)但这最终只会搜索今天与那些时间的日期。 最佳答案 您需要使用PostgreSQL'sdate_part/extractfunction从created_at中提取小时

  10. ruby-on-rails - Rails 单选按钮 - 模型中多列的一种选择 - 2

    我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模

随机推荐