Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MKMapView不';轻敲时,引脚上不会显示弹出窗口_Ios_Objective C_Uiscrollview_Mkmapview - Fatal编程技术网

Ios MKMapView不';轻敲时,引脚上不会显示弹出窗口

Ios MKMapView不';轻敲时,引脚上不会显示弹出窗口,ios,objective-c,uiscrollview,mkmapview,Ios,Objective C,Uiscrollview,Mkmapview,我有一个uicrollview(灰色)和一个UIView(白色)连接在一起。在视图上,我附加了一个MKMapView,里面有一个插针 不知什么原因,该引脚在点击时不显示弹出窗口。 下面是一些代码: UIView * whiteMapView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)]; whiteMapView.backgroundColor = [UIColor whiteColor];

我有一个
uicrollview
(灰色)和一个
UIView
(白色)连接在一起。在视图上,我附加了一个
MKMapView
,里面有一个插针

不知什么原因,该引脚在点击时不显示弹出窗口。 下面是一些代码:

        UIView * whiteMapView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        whiteMapView.backgroundColor = [UIColor whiteColor];
        whiteMapView.clipsToBounds = NO;
        whiteMapView.userInteractionEnabled = YES;
        [self.scrollView addSubview:whiteMapView];

        x = 10.0f;
        y = x;
        w = CGRectGetWidth(whiteMapView.frame) - (x * 2);
        h = w;

        self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        self.mapView.delegate = self;
        self.mapView.scrollEnabled = NO;
        [whiteMapView addSubview:self.mapView];


        [self.mapView removeAnnotations:self.mapView.annotations];

        Shop * shop = [[Shop alloc] init];
        shop.name = self.userInfo[@"shopName"];
        shop.shopDescription = self.userInfo[@"goods_description"];
        shop.latitude = self.userInfo[@"lat"];
        shop.longitude = self.userInfo[@"lon"];

        MapPin * pin = [[MapPin alloc] initWithShop:shop];
        [self.mapView addAnnotation:pin];
这里是委托方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation
{
    if (annotation == mapView.userLocation)
    {
        return nil;
    }
    else
    {
        MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
        pinView.userInteractionEnabled = YES;
        pinView.image = [UIImage imageNamed:@"pin_mappa_red"];
        pinView.canShowCallout = YES;
        pinView.animatesDrop = NO;

        UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        disclosureButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        disclosureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [disclosureButton addTarget:self action:@selector(didPressPin:) forControlEvents:UIControlEventTouchUpInside];
        disclosureButton.tag = [[[(MapPin *)annotation shop] idshop] intValue];

        pinView.rightCalloutAccessoryView = disclosureButton;

        return pinView;
    }
}
在应用程序的另一部分中,此代码可以完美地工作

想法


尝试像下面这样更改注释视图

-(MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:
(id <MKAnnotation>)annotation {

    MKPinAnnotationView *pinView = nil; 

    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    if(annotation) 
    {
        UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        UIImageView *imageInMap = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"net.png"]];

        [disclosureButton addTarget:self action:@selector(mapCallOutPressed) forControlEvents:UIControlEventTouchUpInside];


        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[self.locationMapVIew dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinView.pinColor = MKPinAnnotationColorGreen; 

        pinView.rightCalloutAccessoryView = disclosureButton;
        pinView.leftCalloutAccessoryView = imageInMap;
        pinView.leftCalloutAccessoryView.frame = CGRectMake(0, 0, 35, 35);
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
    } 
    else {
        [self.locationMapVIew.userLocation setTitle:@"I am here"];
    }
    return pinView;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:
(id)注释{
MKPinAnnotationView*pinView=nil;
if([annotation isKindOfClass:[MKUserLocation类]])
返回零;
如果(注释)
{
UIButton*DispositionButton=[UIButton Button类型:UIButtonTypedTailDisposition];
UIImageView*imageInMap=[[UIImageView alloc]initWithImage:[UIImageName:@“net.png”];
[披露按钮添加目标:自我操作:@选择器(MapCallout按下)用于控制事件:UIControlEventTouchUpInside];
静态NSString*defaultPinID=@“com.invasivecode.pin”;
pinView=(MKPinAnnotationView*)[self.locationMapVIew出列可重用AnnotationViewWithIdentifier:defaultPinID];
如果(pinView==nil)pinView=[[[MKPinAnnotationView alloc]
initWithAnnotation:annotation重用标识符:defaultPinID]autorelease];
pinView.pinColor=MKPinAnnotationColorGreen;
pinView.rightCalloutAccessoryView=披露按钮;
pinView.leftCalloutAccessoryView=imageInMap;
pinView.leftCalloutAccessoryView.frame=CGRectMake(0,0,35,35);
pinView.canShowCallout=是;
pinView.animatesDrop=是;
} 
否则{
[self.locationMapVIew.userLocation setTitle:@“我在这里”];
}
返回pinView;
}

检查此方法是否为调用

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSLog("Pin called");
}

如果未调用此方法,则mapview或批注可能存在任何问题。

否,pin仍然不可读取!是,pin不接收触摸事件检查您是否添加了地图视图。userInteractionEnabled=否;或者在xibI中取消选中userInteractionEnabled选项。我已经反复检查了一遍,但对我来说一切正常。我从另一个视图复制了代码,它工作得非常好!请张贴您的答案,以便对其他人有用