开发者

MKAnnotation shows it's Custom Marker graphic in simulator but not on device

开发者 https://www.devze.com 2023-02-06 04:37 出处:网络
I had this working very early, but then it stopped and I have no idea why. Here is the code: - (void)updateMarkers:(NSMutableArray *)myAudioLocationVOArray

I had this working very early, but then it stopped and I have no idea why. Here is the code:

- (void)updateMarkers:(NSMutableArray *)myAudioLocationVOArray
{
 [self cleanupMarkers];

 NSLog(@"UPDATE ALL MARKERS");

 int tArrayCount = [myAudioLocationVOArray count];

 for (int i=0; i< tArrayCount; i = i + 1)
 {
  AudioLocationVO* tAudioLocVO = [myAudioLocationVOArray objectAtIndex:i];

  AudioAnnotation *tNewAnn = [[AudioAnnotation alloc] init];
  tNewAnn.coordinate = CLLocationCoordinate2DMake(tAudioLocVO.latitude, tAudioLocVO.longitude);
  // add current track if available
  tNewAnn.audioLocationVORef = tAudioLocVO;

  [self.mapView addAnnotation:tNewAnn];

  [tNewAnn release];
 }

}

- (void)cleanupMarkers
{
 NSLog(@"REMOVE ALL MARKERS");
 NSArray *tExistingPoints = self.mapView.annotations;
 if ([tExistingPoints count] > 0)
 {
  [self.mapView removeAnnotations:tExistingPoints];
 }
}


- (MKAnnotationView *)mapView:(MKMapView *)myMapView viewForAnnotation:(id <MKAnnotation>)myAnnotation
{

 if ([myAnnotation isKindOfClass:[AudioAnnotation class]])
    {
  AudioAnnotation *tAnnotation = (AudioAnnotation *)myAnnotation;

   MKAnnotationView *tNewMarkerView = [[[MKAnnotationView alloc] initWithAnnotation:tAnnotation reuseIdentifier:nil] autorelease];

   if(tAnnotation.audioLocationVORef.state == ANNOTATION_STATE_DROPPING)
   {
    NSLog(@"ADD DROP MARKER");
    [tNewMarkerView setImage:[UIImage imageNamed:@"greenmarker.png"]];
    tNewMarkerView.draggable = YES;
   }
   else
   {
    NSLog(@"ADD NEW MARKER");
    [tNewMarkerView setImage:[UIImage imageNamed:@"newMarker.png"]];
    tNewMarkerView.draggable = NO;
   }

   tNewMarkerView.frame = CGRectMake(tNewMarkerView.frame.origin.x,tNewMarkerView.frame.origin.y,20,26);

   tNewMarkerView.canShowCallout = YES;
   tNewMarkerView.enabled = YES;


   // callout button
   UIButton *tButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
   tNewMarkerView.rightCalloutAccessoryView = tButton;


   // cover art and title/subtitle
   UIButton *tCover = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
   if(tAnnotation.audioLocationVORef.trackVO==nil)
   {
    tAnnotation.title = @"Drop a Track";
    tAnnotation.subtitle = @"Choose a track to drop";
    [tCover setImage:[UIImage imageNamed:@"preCover.png"] forState:UIControlStateNormal];
   }
   else
   {
    tAnnotation.title = tAnnotation.audioLocationVORef.trackVO.songTitle;
    tAnnotation.subtitle = tAnnotation.audioLocationVORef.trackVO.artist;

    NSLog(@"ADD DATA MARKER %@", tAnnotation.title);
    if(tAnnotation.audioLocationVORef.state==ANNOTATION_STATE_DROPPING){
     tAnnotation.subtitle = 开发者_JS百科@"Touch submit to Drop";
    }
    [tCover setImage:[tAnnotation.audioLocationVORef.trackVO getCoverArt] forState:UIControlStateNormal];
   }
   // make cover enabled to see song detail?
   tCover.enabled = NO;

   tNewMarkerView.leftCalloutAccessoryView = tCover;

   [tCover release];

  return tNewMarkerView;
 }
 return nil;

}

I tried to delete and add again the graphics as assets. I have been playing around a bit with the frame property. So far no luck.

And why the difference between simulator and device. I am using SDK 4.2... on iPhone 4


Make sure the image filenames match exactly with the resource names including upper/lower-case.

For example, if the resource is "GreenMarker.png", then "greenmarker.png" will only work on the simulator and not on the device.

Apple QA1697 (Why doesn't my device load a file that loads fine in the Simulator?) says:

Case-sensitivity: iPhone OS uses a case-sensitive file system, unlike the Simulator which uses a case-insensitive file system by default. Make sure the case-sensitivity of resources accessed within code matches the filename case-sensitivity.


True, they should, but the Mac is case-preserving but also case-insensitive. The simulator runs on the Mac, so that's what you get.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号