且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多个注释都存在获取所选索引注释的问题

更新时间:2022-10-31 12:33:31

calloutAccessoryControlTapped委托方法中,使用view.annotation访问被点击的注释.

In the calloutAccessoryControlTapped delegate method, use view.annotation to access the annotation that was tapped.

如果您有一个自定义注释类,则可以对其进行强制转换以方便地访问属性(您可能还需要先检查被点击的注释是否是您感兴趣的类的实例,如果您感兴趣,则很重要使用多个注释类):

If you have a custom annotation class, you can cast it to easily access the properties (you may also want to first check if the annotation tapped is an instance of the class you're interested in--important if you're using multiple annotation classes):

if ([view.annotation isKindOfClass:[TagMark class]]) {
    TagMark *tm = (TagMark *)view.annotation;
    NSLog(@"tm.someProperty = %@", tm.someProperty);
}