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

时间:2014-07-03 02:03:58

标签: ios objective-c uitableview mkannotation

我的程序会在用户移动一定距离后向地图添加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];

这是G5MapPoint.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中删除带坐标的行时,我希望它还删除与该行相关的相应放置引脚。我在考虑比较时间戳和删除引脚与时间戳类似于行中的时间戳,但不确定这是否是一个很好的方法。有人有任何建议可以解决这个问题吗?谢谢你们

0 个答案:

没有答案