2014-08-31 176 views
0

我有一個應用程序,其中我使用MKMapView來顯示200個引腳。來自引腳的數據來自核心數據,我有一個Objective-C類別的核心數據對象的NSManagedObject子類將它們擴展爲MKAnnotation,這樣我就可以直接從Core Data中將獲取的對象數組添加到Map視圖中。問題是,由於引腳彼此非常接近,我開始使用CCHMapClusterController,並且引腳對象不再是類別,它們被轉換爲CCHMapClusterAnnotation對象。我之前在viewForAnnotation中只是從引腳抓取NSManagedObject子類(位置),但由於引腳對象不再是位置對象,它們是CCHMapClusterObjects,所以我不能再這樣做。這裏是我的老viewForAnnotation:CCHMapClusterController與核心數據NSManagedObject子類

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:  (id<MKAnnotation>)annotation { 
static NSString *reuseID = @"EAnnotation"; 
MKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseID]; 
if ([annotation isKindOfClass:[Location class]]) { 

if (!view) { 
    view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseID]; 
    view.canShowCallout = YES; 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 46, 46)]; 

    Location *location = (Location *)annotation; 

    [imageView setImage:location.smallpic]; 

    view.leftCalloutAccessoryView = imageView; 

    view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    } 

    } 

    return view; 
} 

我的問題是,我怎麼能獲得這位置對象被挖掘出來,當你在地圖中所有的方式放大嗎?我理解你什麼時候縮小引腳不是對象類型的位置,但是當我放大時,我應該能夠訪問我正在點擊的位置對象。

回答

0

CCHMapClusterAnnotation有一個名爲annotations的屬性,其中包含此羣集中的註釋對象數組(您的案例中的核心數據對象)。

請參閱this example如果您想根據羣集中註釋的數量顯示不同的圖釘圖標。這個想法是,您使用一個自定義註釋視圖的集羣和註釋視圖內,你決定什麼圖標顯示。

注意:我是CCHMapClusterController的作者 - 如果您有更多問題,請隨時與我聯繫。

相關問題