Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 删除tableview中的行时,如何删除相应的MKAnnotation?_Ios_Objective C_Uitableview_Mkannotation - Fatal编程技术网

Ios 删除tableview中的行时,如何删除相应的MKAnnotation?

Ios 删除tableview中的行时,如何删除相应的MKAnnotation?,ios,objective-c,uitableview,mkannotation,Ios,Objective C,Uitableview,Mkannotation,在用户移动一定距离后,我的程序将在地图上添加1个插针(显示坐标、速度和时间戳)。在添加接点的同时,它还将相应的坐标添加到UITableView 这是G5MapViewController.m中代码的一部分 G5MapPoint *mp = [[G5MapPoint alloc] initWithCoordinate:coord title:@"Your Trail" speed:resultStr]; [worldView addAnnotation:mp]; MKCoordinateReg

在用户移动一定距离后,我的程序将在地图上添加1个插针(显示坐标、速度和时间戳)。在添加接点的同时,它还将相应的坐标添加到UITableView

这是G5MapViewController.m中代码的一部分

G5MapPoint *mp = [[G5MapPoint alloc] initWithCoordinate:coord title:@"Your Trail" speed:resultStr];

[worldView addAnnotation:mp];

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 300, 300);
[worldView setRegion:region animated:YES];

float latitude = coord.latitude;
float longitude = coord.longitude;
count += 1;

NSString *coordString = [NSString stringWithFormat:@"%d: %f, %f", count, latitude, longitude];
G5SharedStore *store = [G5SharedStore sharedStore];
//Create an NSMutableArray
[[G5SharedStore sharedStore]create:coordString];
这是G5MM.m中代码的一部分

- (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t speed:(NSString *)s
{
    self = [super init];
    if (self) {
        coordinate = c;
        [self setTitle:t];

        /*NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
        [dateFormat setTimeStyle:NSDateFormatterMediumStyle];
        [dateFormat setDateStyle:NSDateFormatterMediumStyle];

        NSDate *date = [NSDate date];
        [self setSubtitle:[NSString stringWithFormat:@"%@", [dateFormat stringFromDate:date]]];*/

        [self setSubtitle:s];
    }
    return self;
}
这是我的G5DetailViewController

    G5SharedStore *store = [G5SharedStore sharedStore];
    //Determine the last row in the array
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:store.allCoords.count inSection:0];
    //Insert row into the table
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@" UITableViewCell"];
    [self.tableView reloadData];

现在,当我在tableView中删除带有坐标的行时,我希望它也删除与该行连接的相应插针。我正在考虑比较时间戳并删除时间戳与行中时间戳类似的pin,但不确定这是否是一个好方法。有人对解决这个问题有什么建议吗?谢谢大家

将注释放入NSMutableArray,其中索引与行索引相同。当您删除一行时,您只需从映射中删除相应的注释并将其从数组中删除即可,因此您无需每次调用
registerClass
——仅在
viewDidLoad
中调用一次,这意味着,我必须首先将注释添加到数组中,然后从数组中将它们添加到映射中。这将使我能够通过访问数组来删除它们?我将如何从地图中删除注释?如果我使用[mapView removeAnnotation:[self.annotationArray objectAtIndex:index]];我收到此错误“由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\uu NSCFString setRowIndex:]:发送到实例0x1a1cc680的选择器无法识别”。请告诉我…该异常意味着您已对NSString调用了
setRowIndex
方法。你在数组里放了什么?请更新您的问题以显示您的新代码