मेरे पास एनोटेशन के साथ एक नक्शा दृश्य है, और ये एनोटेशन कॉलआउट प्रदर्शित करते हैं। जब कॉलआउट का प्रकटीकरण विवरण बटन क्लिक किया जाता है, तो यह एक नए दृश्य में बैठता है।MKMapView एनोटेशन बदलना/खोना आदेश?
मेरा एमकेएएनोटेशन एक कस्टम क्लास है जो <MKAnnotation>
लागू करता है। आइए क्लास माई क्लास को कॉल करें। वे एक एनएसएमयूटेबलएरे में संग्रहित होते हैं। इस दृश्य के व्यूलोड के दौरान, मैं इस सरणी में मैप क्लास की एनोटेशन में MyClass के प्रत्येक ऑब्जेक्ट को जोड़ता हूं। डीबगर का उपयोग करके, मैं देख सकता हूं कि यह सब जोड़ने के बाद, [self.MapView एनोटेशन] ऑर्डर NSMutableArray जैसा ही है।
अब मैप के भीतर एक और ब्रेकपॉइंट सेट किया गया व्यू: व्यूफोर नोटेशन: और 1 के ऑर्डर को देखें) मेरे एनएसएमयूटेबलएरे और 2) [self.MapView एनोटेशन]। सरणी एक ही क्रम में निश्चित रूप से है। हालांकि, एनोटेशन का आदेश खराब हो गया है।
यह मेरे लिए एक बड़ी समस्या थी, क्योंकि मुझे MyClass के विशिष्ट उदाहरण का उपयोग करने की आवश्यकता थी जिसे उपयोगकर्ता ने अगले दृश्य में चुना था। एकेए, मैं एनोटेशन को देखना चाहता था, इसकी अनुक्रमणिका ढूंढना चाहता था, और फिर सरणी के भीतर एक ही इंडेक्स प्राप्त करने के लिए इसका उपयोग करना चाहता था।
अब मुझे एहसास हुआ है कि मैं सिर्फ एनोटेशन को सीधे सहेज सकता हूं (एंड्रॉइड पृष्ठभूमि से आ रहा है, यह मेरे लिए बहुत अच्छा था)। हालांकि, मैं अभी भी एक नुकसान में अवधारणात्मक रूप से हूं कि आदेश क्यों खराब हो गया। क्या कोई मेरी मदत कर सकता है? नीचे दिए गए कोड:
- (void)viewDidLoad
{
if([fromString isEqualToString:@"FromList"])
self.navigationItem.hidesBackButton = TRUE;
else {
self.navigationItem.rightBarButtonItem = nil;
}
self.array = [MySingleton getArray];
//set up map
//declare latitude and longitude of map center
CLLocationCoordinate2D center;
center.latitude = 45;
center.longitude = 45;
//declare span of map (height and width in degrees)
MKCoordinateSpan span;
span.latitudeDelta = .4;
span.longitudeDelta = .4;
//add center and span to a region,
//adjust the region to fit in the mapview
//and assign to mapview region
MKCoordinateRegion region;
region.center = center;
region.span = span;
MapView.region = [MapView regionThatFits:region];
for(MyClass *t in self.array){
[MapView addAnnotation:t];
}
[super viewDidLoad];
}
//this is the required method implementation for MKMapView annotations
- (MKAnnotationView *) mapView:(MKMapView *)thisMapView
viewForAnnotation:(MyClass *)annotation
{
static NSString *identifier = @"MyIdentifier";
//the result of the call is being cast (MKPinAnnotationView *) to the correct
//view class or else the compiler complains
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[thisMapView
dequeueReusableAnnotationViewWithIdentifier:identifier];
if(annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
}
annotationView.pinColor = MKPinAnnotationColorGreen;
//pin drops when it first appears
annotationView.animatesDrop=TRUE;
//tapping the pin produces a gray box which shows title and subtitle
annotationView.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = infoButton;
return annotationView;
}
अपने अंतिम बिंदु के लिए धन्यवाद। हमेशा –