如何添加uitextfield& MKPinAnnotationView标注中的一个uibutton?

时间:2013-05-23 06:45:45

标签: iphone mkmapview mkannotation callouts

我想知道是否有办法添加UITextField&在UIButton标注气泡中MKPinAnnotationView,如果用户点击了按钮,它会调用某种方法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码添加自定义视图而不是MKAnnotationView ..

您可以使用addSubview属性添加任何控件...

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKAnnotationView *customPinView = nil; 
    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( customPinView == nil ) 
            customPinView = [[MKAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        customPinView.canShowCallout = YES;
        //customPinView.animatesDrop = YES;
        customPinView.image = [UIImage imageNamed:@"yourImageName"];//write your imagename 
        // and add UIButton with bellow code
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                            action:@selector(ShowStoreDetail:)
                  forControlEvents:UIControlEventTouchUpInside];
        customPinView.rightCalloutAccessoryView = rightButton;here
    } 
    else {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

我希望它对你有用......

:)