MKAnnotation 在模拟器中显示其自定义标记图形,但不在设备上显示

发布于 2024-10-14 04:55:15 字数 3074 浏览 2 评论 0原文

我很早就开始工作了,但后来就停止了,我不知道为什么。这是代码:

- (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 = @"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;

}

我尝试删除并再次添加图形作为资产。我一直在玩弄框架属性。到目前为止还没有运气。

以及为什么模拟器和设备之间存在差异。我在 iPhone 4 上使用 SDK 4.2...

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 = @"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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

究竟谁懂我的在乎 2024-10-21 04:55:15

确保图像文件名与资源名称完全匹配,包括大小写。

例如,如果资源是“GreenMarker.png”,则“greenmarker.png”只能在模拟器上运行,而不能在设备上运行。

Apple QA1697(为什么我的设备无法加载可以正常加载的文件模拟器?) 说:

区分大小写:iPhone OS 使用
区分大小写的文件系统,与
模拟器使用了
不区分大小写的文件系统
默认。确保
访问的资源区分大小写
代码内匹配文件名
区分大小写。

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.

笛声青案梦长安 2024-10-21 04:55:15

确实,他们应该这样做,但 Mac 保留大小写,但也不区分大小写。模拟器在 Mac 上运行,所以这就是您所得到的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文