2012-04-30 35 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; 
} 

這裏是一個應該被調用的方法:

// 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:發送器:是不一樣的方法。您的prepareForSegue:sender:方法中的placeName和friends也是未知的(或者是ivars)。

我會從根本上改變prepareForSegue:發件人:方法並將其更改爲

- (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]]; 

    } 
} 

,並調用它以同樣的方式,只是改變調用

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

而如果選擇的名稱你進入註釋和地圖,你不應該使用更簡單導航的segues。

0

你有兩種詳細視圖控制器的出現,在MoreDetailViewController你代碼,並在你的錯誤DetailViewController。是否有可能將它們混合起來?

相關問題