我一直在琢磨MKMapView相當長一段時間,試圖更熟悉它並且遇到了問題。MKPinAnnotationView一次加載didSelectAnnotationView方法中的所有數據
我有我的MapView填充兩個引腳,當我按他們,他們有他們各自的註釋。我也有一個按鈕,將帶我到一個新的UIView UlLabels將加載數組中的數據。
看着我的控制檯,我注意到數據正在通過,而不是它只是針對我選擇其加載所有的引腳,然後顯示最後一個。
這裏是我的我使用加載數據的下一個視圖的方法代碼:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:addAnnotation reuseIdentifier:@"currentloc"];
if(annView.tag = 0) {
GSStore * theStore = [globalCMS getStoreById:1];
NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
int storeid = theStore.storeid;
[prefs setInteger:storeid forKey:@"selectedstore"];
NSLog(@"%@", theStore.name);
storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];
}
if(annView.tag = 1){
GSStore * theStore = [globalCMS getStoreById:2];
NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
int storeid = theStore.storeid;
[prefs setInteger:storeid forKey:@"selectedstore"];
NSLog(@"%@", theStore.name);
storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];
}
if (annView.tag = 2) {
GSStore * theStore = [globalCMS getStoreById:3];
NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
int storeid = theStore.storeid;
[prefs setInteger:storeid forKey:@"selectedstore"];
NSLog(@"%@", theStore.name);
storeName.text = [NSString stringWithFormat:@"%@", theStore.name];
storeCS.text = [NSString stringWithFormat:@"%@,%@", theStore.city, theStore.state];
storeHours.text = [NSString stringWithFormat:@"%@", theStore.hours];
storePhone.text = [NSString stringWithFormat:@"%@", theStore.phone];
storeAddress.text = [NSString stringWithFormat:@"%@", theStore.address];
storeCSZ.text = [NSString stringWithFormat:@"%@,%@ %@", theStore.city, theStore.state, theStore.zip];
storeWebsite.text = [NSString stringWithFormat:@"%@", theStore.website];
}
}