2013-02-07 197 views
0

我想我的代碼有問題,但我找不到它。canShowCallout按鈕不起作用

我想與在leftCalloutAccessoryView按鈕,一個單一的點擊切換視圖,但我得到總是相同的錯誤:

NSInvalidArgumentException', reason: ' 
-[ThirdViewController showDetailView:]: unrecognized selector sent to instance 

這裏我的代碼:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     return nil; 
    } 
    else 
    { 
     MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"]; 
     annotationView.canShowCallout = YES; 
     UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

     [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside]; 
     annotationView.rightCalloutAccessoryView=detailButton; 
     annotationView.enabled = YES; 

     UIImage *image = [UIImage imageNamed:@"logo.jpeg"]; 
     UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; 
     annotationView.leftCalloutAccessoryView = imgView; 
     annotationView.image = [UIImage imageNamed:@"pin.png"]; 
     return annotationView; 
    } 
} 
- (IBAction)detailButton:(UIButton *)sender 
{ 
    ThirdViewController *infoView = [[ThirdViewController alloc] init]; 
    [self.navigationController pushViewController:infoView animated:YES]; 
    NSLog(@"pushed Button!!!!!!"); 

} 

從我的故事板的小截圖:

enter image description here

感謝您的幫助!

問候CTS

回答

2

addTarget,代碼表示,按鈕應調用方法showDetailView:

[detailButton addTarget:self action:@selector(showDetailView:) forControlEvents... 

但有沒有這樣的方法(這是什麼錯誤意味着)。


改變這個方法的名字來源於:

- (IBAction)detailButton:(UIButton *)sender 

到:

- (IBAction)showDetailView:(UIButton *)sender