4

我在地图视图中创建BubbleView。在气泡中,我已经放置了按钮,但我没有点击按钮。

我该如何实施请帮助我。

我努力了.......

customCalloutView.h

#import <UIKit/UIKit.h>

@interface customCalloutView : UIView
@property (nonatomic, retain) IBOutlet UIButton *BubbleBtn;

customCalloutView.m

#import "customCalloutView.h"

 @implementation customCalloutView
 {

 }
 @end 

另一个类中mapview的委托方法

- (MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    static NSString *identifier=@"MyAnnotation";
    NSLog(@"anotioni s:%@",annotation);
    //CLLocationCoordinate2D pinCoordinate = [self.pickupLocationView convertPoint:CGPointMake(self.pickupLocationView.frame.size.width / 2, self.pickupLocationView.frame.size.height) toCoordinateFromView:self.view];

    MKAnnotationView *annotationView=(MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (!annotationView)
    {
        annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:identifier];
        annotationView.image=[UIImage imageNamed:@"mapPin"];
    } else
    {
        annotationView.annotation=annotation;
    }
    return annotationView;
}

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    customCalloutView *callOutView=nil;
    callOutView.userInteractionEnabled=YES;

    if (callOutView == nil)
    {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"customCalloutView" owner:self options:nil];
        callOutView=[nib objectAtIndex:0];
    }
    [callOutView.BubbleBtn addTarget:self action:@selector(BtnDetailclick:) forControlEvents:UIControlEventTouchUpInside];

    CGRect callOutViewFrame=callOutView.frame;
    callOutViewFrame.origin=CGPointMake(-callOutViewFrame.size.width/2+14 , -callOutViewFrame.size.height);
    callOutView.frame=callOutViewFrame;
   // [callOutView.BtnDetail setTitle:@"Change" forState:UIControlStateNormal];
    [view addSubview:callOutView];

}
-(IBAction)BtnDetailclick:(UIButton *)sender
{
    NSLog(@"Hello");
}
4

0 回答 0