自定义注释上的按钮

时间:2013-01-31 10:38:20

标签: iphone xcode

我创建了一个自定义注释,右侧有一个按钮,左侧有一个标签。

它显示良好且标签文字正在完美变化,但出于某种原因,当我点击按钮时它没有反应。我已将IBAction连接到它,它应该工作。但它只是不叫我的IBAction。

有没有人知道为什么这个按钮忽略了我的触摸?

谢谢,

1 个答案:

答案 0 :(得分:0)

         (MKAnnotationView *)mapView:(MKMapView *)aMapView 
                  viewForAnnotation:(id)ann 
         { 

         NSString *identifier = @”myPin”; 
         MKPinAnnotationView *pin = (MKPinAnnotationView *) 
         [aMapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
         if (pin == nil) { 
              pin = [[[MKPinAnnotationView alloc] initWithAnnotation:ann 
                                                           reuseIdentifier:identifier] 
                      autorelease]; 
         } else { 
              pin.annotation = ann; 
         } 


         //---display a disclosure button on the right--- 
         UIButton *myDetailButton = 
         [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
         myDetailButton.frame = CGRectMake(0, 0, 23, 23); 
         myDetailButton.contentVerticalAlignment = 
         UIControlContentVerticalAlignmentCenter; 
         myDetailButton.contentHorizontalAlignment = 
         UIControlContentHorizontalAlignmentCenter; 

         [myDetailButton addTarget:self 
                               action:@selector (checkButtonTapped:) 
                    forControlEvents:UIControlEventTouchUpInside]; 

         pin.rightCalloutAccessoryView = myDetailButton; 
         pin.enabled = YES; 
         pin.animatesDrop=TRUE; 
         pin.canShowCallout=YES; 

         return pin; 
    } 



    -(void) checkButtonTapped:(id) sender
      { 

       //---know which button was clicked; 
       // useful for multiple pins on the map--- 
       // UIControl *btnClicked = sender; 
       UIAlertView *alert = 
       [[UIAlertView alloc] initWithTitle:@”Your Current Location” 
                                       message :location 
                                      delegate:self 
                           cancelButtonTitle:@”OK” 
                           otherButtonTitles:nil]; 
       [alert show]; 
       [alert release]; 
       } 

我在我的项目中使用此代码,它对我来说很好,所以你可以试试这个。

相关问题