How to add a custom CalloutView loaded from nib file

三世轮回 提交于 2019-12-02 18:07:49

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8945376/how-to-add-a-custom-calloutview-loaded-from-nib-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!