我一直在研究 MKMapView 很长一段时间,试图更熟悉它,但遇到了一个问题。
我的 MapView 填充了两个引脚,当我按下它们时,它们有各自的注释。我还有一个按钮,它将带我到一个带有 UlLabels 的新 UIView,该 UIView 将加载来自数组的数据。
看着我的控制台,我注意到数据正在通过,但我选择了它加载所有这些数据,然后显示最后一个,而不是仅仅针对 pin。
这是我用来为下一个视图加载数据的方法的代码:
- (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];
}
}