2012-04-30 2 views
1

터치했을 때 MoreDetailViewController를 스택에 가져와야하는 세부 공개 표시기가있는 mapView가 있습니다. 현재 인스턴스 오류로 전송 된 인식 할 수없는 선택기와 충돌합니다.세부 공개 표시자가 접촉했을 때 Mapview 주석이 충돌 함

이 방법을 공개 표시기 프레스에서 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 호출하는 방법을 알아 내려고하고 있습니다. 여기

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *mapPin = nil; 
    if(annotation != map.userLocation) 
    { 
     static NSString *defaultPinID = @"defaultPin"; 
     mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (mapPin == nil) 
     { 
      mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                 reuseIdentifier:defaultPinID]; 
      mapPin.canShowCallout = YES; 

      UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      [disclosureButton addTarget:self action:@selector(prepareForSegue:) forControlEvents:UIControlEventTouchUpInside]; 

      mapPin.rightCalloutAccessoryView = disclosureButton; 

     } 
     else 
      mapPin.annotation = annotation; 

    } 
    return mapPin; 
} 

가 호출하는 메소드입니다 : 여기

는 공개 표시와 함께지도 주석 코드입니다, 당신이 상세 뷰 컨트롤러의 두 종류가있는 MoreDetailViewController

// Do some customisation of our new view when a table item has been selected 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Make sure we're referring to the correct segue 
    if ([[segue identifier] isEqualToString:@"ShowMoreInfo"]) { 

     // Get reference to the destination view controller 
     MoreDetailViewController *mdvc = [segue destinationViewController]; 


     [mdvc setSelectedItemName:[NSString stringWithFormat:@"%@", placeName.text]]; 
     [mdvc setSelectedItemAddress:[NSString stringWithFormat:@"%@", placeFormattedAddress.text]]; 

     [mdvc setSelectedItemWeb:[NSString stringWithFormat:@"%@", placeWebsite.text]]; 
     [mdvc setSelectedItemRating:[NSString stringWithFormat:@"%@", placeRating.text]]; 
    //  [mdvc setSelectedItemDistance:[NSString stringWithFormat:@"%@", placeDistance.text]]; 

    } 
} 
+0

다음은 오류입니다. *** 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인해 응용 프로그램을 종료합니다. 이유 : '- [DetailViewController prepareForSegue :] : 인스턴스 0x81bbb30에 전송 된 인식 할 수없는 선택기' – hanumanDev

답변

0

prepareForSegue : 및 prepareForSegue : sender :는 같은 방법이 아닙니다. 또한 prepareForSegue : sender : 메소드의 placeName 및 friends는 알 수 없습니다 (또는 ivars 임). 단지

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

그리고 만약에라는 선택기의 이름을 변경, 같은 방식으로 방법

- (void)showMoreInfo:(id)sender{ 
     // Get reference to the destination view controller 
     MoreDetailViewController *mdvc = [segue destinationViewController]; 

//define and set the placename and other variables 

     [mdvc setSelectedItemName:[NSString stringWithFormat:@"%@", placeName.text]]; 
     [mdvc setSelectedItemAddress:[NSString stringWithFormat:@"%@", placeFormattedAddress.text]]; 

     [mdvc setSelectedItemWeb:[NSString stringWithFormat:@"%@", placeWebsite.text]]; 
     [mdvc setSelectedItemRating:[NSString stringWithFormat:@"%@", placeRating.text]]; 
    //  [mdvc setSelectedItemDistance:[NSString stringWithFormat:@"%@", placeDistance.text]]; 

    } 
} 

로 변경 그리고 전화 : 보낸 사람 :

나는 근본적으로 prepareForSegue을 바꿀 것 당신은 주석과지도에있어, 당신은 간단한 탐색을 위해 더 많은 segues를 사용하면 안됩니다.

0

당신의 코드 및 DetailViewController을 입력하십시오. 당신이 그들을 섞어 버릴 가능성이 있습니까?

관련 문제