如何添加从 nib 文件加载的自定义 CalloutView
我正在尝试为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自定义 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
我找到了解决问题的方法: gik-animated-callout
I found a solution for my problem: gik-animated-callout