通过coredata实体绑定注释

时间:2014-12-01 20:47:08

标签: ios objective-c core-data

我使用下面的代码将地图中的注释绑定到“contacts”实体

//add each object in Contacts entity to map view
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"Contacts" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:nil];
for (NSManagedObject *info in fetchedObjects) {
    NSLog(@"Name: %@", [info valueForKey:@"name"]);

    //initializetion latitude and longitude
    aLng=[[info  valueForKey:@"lng"] doubleValue];
    aLat=[[info  valueForKey:@"lat"] doubleValue];

    //if latitude and longitude not null
    if(aLng && aLat && aLng!=0.0 &&aLat!=0.0)
    {
        //create a new Coordinate
        CLLocationCoordinate2D wimLocation;
        wimLocation.latitude=aLat;
        wimLocation.longitude=aLng;

        //create a new Annotation and initializetion it
        MKPointAnnotation * myAnnotation=[MKPointAnnotation alloc];
        myAnnotation.coordinate=wimLocation;
        myAnnotation.title=[info valueForKey:@"name"];


        //add create Annotation to mapview
        [self.mapview addAnnotation:myAnnotation];

    }    
}

它的工作非常好,但我必须解决问题 - 我想要展示

[UIImage imageWithData:[info valueForKey:@"photo"]] 

而不是图片图片2-如何在地图上选择联系人(注释)来执行某些操作

1 个答案:

答案 0 :(得分:0)

使用MKAnnotationView并设置其image属性。