如何添加从 nib 文件加载的自定义 CalloutView

发布于 2024-12-28 03:18:10 字数 785 浏览 2 评论 0原文

我正在尝试为 AnnotationView 制作自定义标注视图。我看过这个答案,似乎是一个很好的解决方案(它有效)。我试图从 nib 文件加载 UIView,并且 UIView 出现,但他的按钮不起作用,不会被按下。

有办法做到这一点吗?如何从 nib 文件加载 UIView 并使按钮正常工作? 或者也许有人帮我找到一个好的解决方案。

谢谢

这是我正在使用的代码:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    if(selected)
    {
        //Add custom view to self...
        calloutView = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil] objectAtIndex:0];
        [self addSubview:calloutView];
    }
    else
    {
        //Remove custom view...
        if (calloutView) {
            [calloutView removeFromSuperview];
        }
    }
}

提前致谢

I'm trying to make a custom Callout view for AnnotationView. I had seen this answer, and seems a good solution (it works). I'm trying to load a UIView from a nib file, and the UIView appears, but his buttons don't work, don't get pushed.

Is there a way of doing this?? How can I load the UIView from a nib file and get the buttons working??
Or maybe anyone help me finding a good solution.

Thanks

Here's the code I'm using:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    if(selected)
    {
        //Add custom view to self...
        calloutView = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil] objectAtIndex:0];
        [self addSubview:calloutView];
    }
    else
    {
        //Remove custom view...
        if (calloutView) {
            [calloutView removeFromSuperview];
        }
    }
}

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2025-01-04 03:18:11

自定义 UIView 的笔尖应该有一个支持 UIView 类 (MyCustomView.h/.m)。在 Interface Builder 中,您需要将身份检查器下的自定义类值设置为您的自定义类。完成此操作后,您可以通过将连接(可能在内部进行触摸)从底部拖动到对象部分下的主视图(而不是您可能习惯的文件所有者),将笔尖中的 UIButton 连接到所需的 IBAction 。

希望有帮助

〜祝你好运

The nib for your custom UIView should have a backing UIView class (MyCustomView.h/.m). In Interface Builder you will want to set the custom class value under the identity inspector to your custom class. Once this is done you would hook up the UIButton in the nib to your desired IBAction by dragging the connection (touch up inside likely) from the bottom to the main view under the objects section (NOT the file's owner as you may be used to).

Hopefully that helps

~Good Luck

软糯酥胸 2025-01-04 03:18:11

我找到了解决问题的方法: gik-animated-callout

I found a solution for my problem: gik-animated-callout

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文