我很早就开始工作,但之后就停止了,我不明白为什么。这是代码:
- (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 ...
答案 0 :(得分:3)
确保图像文件名与资源名称完全匹配,包括大写/小写。
例如,如果资源是“GreenMarker.png”,那么“greenmarker.png”只能在模拟器上工作,而不能在设备上工作。
Apple QA1697 (Why doesn't my device load a file that loads fine in the Simulator?)说:
区分大小写:iPhone OS使用了 区分大小写的文件系统,不像 使用的模拟器 不区分大小写的文件系统 默认。确保 访问资源的区分大小写 在代码中匹配文件名 区分大小写。
答案 1 :(得分:1)
是的,他们应该,但Mac保留了大小写,但也不区分大小写。模拟器在Mac上运行,这就是你得到的。