0

我有一个从 coredata 获取并获取 Location 对象数组的地图视图。位置对象是自定义的 NSManagedObjects,如下所示:

@property (nonatomic, retain) NSString * ciudad;
@property (nonatomic, retain) NSString * horario;
@property (nonatomic, retain) NSString * codigo;
@property (nonatomic, retain) NSString * nombrePublico;
@property (nonatomic, retain) NSString * telefono;
@property (nonatomic, retain) NSString * direccion;
@property (nonatomic, retain) NSString * coordenadas;
@property (nonatomic, retain) NSString * hrs24;
@property (nonatomic, retain) NSString * driveThru;
@property (nonatomic, retain) NSDate * updatedAt;

然后我遍历数组中的所有 Location 对象并创建注释,如下所示:

MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate distance:0];

然后我将这些注释添加到一个数组中,然后通过按一下按钮将它们绘制出来:

- (IBAction)refreshTapped:(id)sender {
    for (id<MKAnnotation> annotation in _mapView.annotations) {
        [_mapView removeAnnotation:annotation];
    }
    for (MyLocation *annotation in self.myLocationsToSort) {
        [_mapView addAnnotation:annotation];   
    }   
}

最后,一旦用户点击标注上的披露按钮,我想将对象传递给 UIViewController。所以首先我创建我的注释:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

然后我会这样做:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

    if (![view.annotation isKindOfClass:[MyLocation class]])
        return;

    [self performSegueWithIdentifier:@"DetailVC" sender:view];

}

segue 调用详细表视图。我的问题是,我应该如何处理将对象传递到详细表视图?

4

2 回答 2

1

performSegueWithIdentifier在保存annotation到成员变量之前在您的地图视图中然后覆盖

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"DetailVC"]) {
        [[segue destinationViewController] setAnnotation:self.annotation];
    }
}
于 2013-05-30T21:29:06.087 回答
0

使用 prepareForSegue 方法并传递它:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"DetailVC"])
{
    YourViewController *vc = [segue destinationViewController];

    // Pass objects to the destination
    [vc setAObjectHere:object];
}
}
于 2013-05-30T21:43:49.757 回答