gpt4 book ai didi

ios - 为什么当我按下 AnnotationView 时图像有时会消失?

转载 作者:行者123 更新时间:2023-11-29 13:25:11 27 4
gpt4 key购买 nike

在我的 MapView 中有多个 annotationView,每个都有自己的图像,有时当我按下图像时,如果不重新加载 viewController,它就会消失并且永远不会回来。为什么会这样?

 - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id 
<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[AnnotationView class]]) {

return nil;
}

if ([annotation isKindOfClass:[AnnotationCustom class]]){


static NSString* AnnotationIdentifier = @"AnnotationIdentifier";

MKPinAnnotationView *annotationView = (MKPinAnnotationView*) [mapView
dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];

annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation

reuseIdentifier:AnnotationIdentifier];

if ([self.nameTable isEqualToString:@"Movies"]){
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){

annotationView.image = [UIImage imageNamed:@"iphone_movies.png"];


}else{
annotationView.image = [UIImage imageNamed:@"ipad_movies.png"];

}


}else if ([self.nameTable isEqualToString:@"Food_Drink"]){
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
annotationView.image = [UIImage imageNamed:@"iphone_foodDrink.png"];


}else{
annotationView.image = [UIImage imageNamed:@"ipad_foodDrink.png"];


}
}else if (......){
//same procedure for all annotationView

}


UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

annotationView.rightCalloutAccessoryView=detailButton;

annotationView.canShowCallout = YES;
annotationView.draggable = YES;

return annotationView;
}

有什么东西不见了吗?

最佳答案

你在做什么吗

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

我还注意到您没有为注释 View 设置注释。设置注释 View 时,您还应该这样做

annotationView.annotation = annotation;

关于ios - 为什么当我按下 AnnotationView 时图像有时会消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307760/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com