Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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
Iphone 检测选定的地图注释Xcode_Iphone_Objective C_Ios_Xcode_Ipad - Fatal编程技术网

Iphone 检测选定的地图注释Xcode

Iphone 检测选定的地图注释Xcode,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我有一张地图,多个注释被放在地图上。当我选择注释并点击“公开”按钮时,会出现一个包含表视图的新视图(DetailViewController)。 我想要的是,当DetailViewController打开时,所选注释的描述直接变为选中 使用委派方法选择注释视图:并将detalViewController推入导航控制器 这将有所帮助。使用此委托方法: - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotatio

我有一张地图,多个注释被放在地图上。当我选择注释并点击“公开”按钮时,会出现一个包含表视图的新视图(DetailViewController)。 我想要的是,当DetailViewController打开时,所选注释的描述直接变为选中


使用委派方法选择注释视图:并将detalViewController推入导航控制器


这将有所帮助。

使用此委托方法:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
      AnnotationView *annotation = (AnnotationView *)mapView.annotation;
      NSInteger *yourIndex = annotation.myindex;
}

然后按下导航控制器

您可以使用以下代码来检测何时在MKMapView中选择了MKAnnotation

@interface ClassVC ()
{
    int notationTag;
} 

- (void)viewDidLoad
{
    notationTag = 0; //initialisation of variable
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    // If it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    // Handle any custom annotations.
    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        // Try to dequeue an existing pin view first.
        MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
        if (!pinView)
        {
            // If an existing pin view was not available, create one.
            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"mallicon.png"];
            pinView.calloutOffset = CGPointMake(0, 32);
            //pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            pinView.tag = notationTag;
        } else {
            pinView.annotation = annotation;
        }
        notationTag++;
        return pinView;
    }
    return nil;
}
在下一个视图中添加这行代码

NSIndexPath *index =[NSIndexPath indexPathWithIndex:[name1Str intValue]];
[tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];
在我的例子中,我使用了下面的代码来重新加载,您也可以尝试一下

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    self.mapView.centerCoordinate = view.annotation.coordinate;
    NSLog(@"======Tag====%ld", (long)view.tag);
    NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:[view tag] inSection:0];
    [self.collectionView scrollToItemAtIndexPath:rowToReload atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}

我这样做了,但是如何让包含所选注释细节的行成为选中的?!我这样做了,但是如何让包含所选注释细节的行成为选中的?!你可以用很多方法做这件事。。您只需为每个注释设置序列号,并将序列号传递给detailViewController。为了设置选定的行,下面的链接将有助于yes dude,我已经给了每个pin一个序列号。但是如何用我选择的一个来检测呢?好的答案它节省了我的时间pinView.tag=i;这个代码太棒了
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    self.mapView.centerCoordinate = view.annotation.coordinate;
    NSLog(@"======Tag====%ld", (long)view.tag);
    NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:[view tag] inSection:0];
    [self.collectionView scrollToItemAtIndexPath:rowToReload atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}