2011-04-05 109 views
1

问候, 我已经进入iOS只有1.5个月了,我希望我不要问一个已经在这里得到解答的问题。那就是:iPhone - 用UITableview didSelectRowAtIndexPath方法显示覆盖图

我的tableview是列出了一些持续时间每个属于包含坐标与时间戳覆盖:

for (NSUInteger i = 0; i < [dataset count]; i++) 
    { 
     crumbPath = [[CrumbPath alloc] initWithCenterCoordinate:mapView.userLocation.coordinate]; //crumbPath is my overlay 

     NSDictionary *route = [dataset objectAtIndex:i]; 
     NSArray *points = [route objectForKey:@"Points"]; 

     for (NSUInteger j = 0; j < [points count]; j++) 
     { 
      NSDictionary *point = [points objectAtIndex:j]; 

      float latitude = (float)([[point objectForKey:@"Latitude"] doubleValue]/1000000); 
      float longitude = (float)([[point objectForKey:@"Longitude"] doubleValue]/1000000); 

      CLLocationCoordinate2D tempCoord = CLLocationCoordinate2DMake(latitude, longitude); 

      [crumbPath addCoordinate:tempCoord]; 
     } 
     [mapView addOverlay:crumbPath]; 
     [crumbPath release]; 
    } 

据我所知,我可以列出我的tableview持续时间,我想现在要做的就是用tableView:didSelectRowAtIndexPath方法来显示在tableview上点击持续时间的叠加层。现在,我的叠加层都显示在mapview上,我只想显示选中的一个。

在此先感谢!

阿里

回答

1

发布我的答案给我被遗忘的问题。

Inside tableView:didSelectRowAtIndexPath:,我只是先删除所有覆盖,并添加索引我从tableview得到的选定的一个。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.mapView removeOverlays:crumbs]; //crumbs - overlay array 
    [self.mapView addOverlay:[crumbs objectAtIndex:[indexPath row]]]; 
} 
0

- (void)removeOverlay:(id <MKOverlay>)overlay可以用来删除不打算再显示的。

+0

感谢您的回复。我很快在didSelectRowAtIndex方法内使用数组发现了我的解决方案。 – 2011-04-05 10:13:46

相关问题