我的問題是,當我點擊引腳上,它給出了相同的引腳相關的錯誤信息。我認爲引腳的索引可能與數組的索引不一樣。點擊地圖針給出錯誤信息
下面是代碼:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.canShowCallout = YES;
if ((annotation.coordinate.latitude == mapLatitude) && (annotation.coordinate.longitude == mapLongitude)) {
if ([estadoUser isEqualToString:@"online"])
{
// NSLog(@"ONLINE");
pinView.image = [UIImage imageNamed:@"1352472516_speech_bubble_green.png"]; //as suggested by Squatch
}else{
//NSLog(@"OFFLINE");
pinView.image = [UIImage imageNamed:@"1352472468_speech_bubble_red.png"];
}
}
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
} else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
-(void)showDetails
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
DMChatRoomViewController *_controller = [storyboard instantiateViewControllerWithIdentifier:@"DmChat"];
[self presentViewController:_controller animated:YES completion:nil];
}
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([view.annotation isKindOfClass:[DisplayMap class]])
{
NSInteger index = [mapView.annotations indexOfObject:view.annotation]
DisplayMap *annotation = (DisplayMap *)view.annotation;
NSMutableDictionary *item = [allMapUsers objectAtIndex:index];
//HERE DOES NOT DISPLAY THE INFO ON THE CORRECT PLACE
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:[[allMapUsers objectAtIndex:index] objectId] forKey:@"userSelecionadoParaChat"];
[standardUserDefaults synchronize];
}
}
-(void)reloadMap
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
for (int i=0; i<allMapUsers.count; i++)
{
NSMutableDictionary *item = [allMapUsers objectAtIndex:i];
NSLog(@"index=%i para objectID=%@",i,[[allMapUsers objectAtIndex:i] objectId]);
if (([[item valueForKey:@"estado"] isEqualToString:@"offline"] && [[defaults stringForKey:@"showOfflineUsers"] isEqualToString:@"no"]) || [[item valueForKey:@"estado"] isEqualToString:@""]) {
}else{
estadoUser = [item valueForKey:@"estado"];
[outletMapView setMapType:MKMapTypeStandard];
[outletMapView setZoomEnabled:YES];
[outletMapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[item valueForKey:@"Latitude"] floatValue];
region.center.longitude = [[item valueForKey:@"Longitude"] floatValue];
region.span.longitudeDelta = 81;
region.span.latitudeDelta = 80;
[outletMapView setRegion:region animated:YES];
/////
mapLatitude = [[item valueForKey:@"Latitude"] floatValue];
mapLongitude = [[item valueForKey:@"Longitude"] floatValue];
CLLocationCoordinate2D locationco = {mapLatitude,mapLongitude};
ann = [[DisplayMap alloc] init];
ann.coordinate = locationco;
ann.title = [item valueForKey:@"username1"];
NSLog(@"ann.title=%@ para objectID=%@",[item valueForKey:@"username1"],[[allMapUsers objectAtIndex:i] objectId]);
ann.subtitle = [item valueForKey:@"estado"];
ann.coordinate = region.center;
[outletMapView addAnnotation:ann];
}
}
}
對不起我的英文不好,如果你不明白的問題,請不要downrate,就問我,我總是繞來回答。
問候
這就是爲什麼你在24.8k。 V.通過回答。 – Craig
謝謝你幫了我很多。 – MonkeyBlue