gpt4 book ai didi

ios - 如何将 MyLocation 对象从 Mapview 传递到 tableview?

转载 作者:行者123 更新时间:2023-11-29 03:53:02 26 4
gpt4 key购买 nike

我有一个从 coredata 获取并获取 Location 对象数组的 map View 。 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;

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

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 调用详细 TableView 。我的问题是,我应该如何处理将对象传递给详细 TableView ?

最佳答案

performSegueWithIdentifier之前在 map View 中将annotation保存到成员变量然后覆盖

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"DetailVC"]) {
[[segue destinationViewController] setAnnotation:self.annotation];
}
}

关于ios - 如何将 MyLocation 对象从 Mapview 传递到 tableview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16845961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com