Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Objective c 从链接到批注的UIAlertView传递信息_Objective C_Xcode_Mapkit - Fatal编程技术网

Objective c 从链接到批注的UIAlertView传递信息

Objective c 从链接到批注的UIAlertView传递信息,objective-c,xcode,mapkit,Objective C,Xcode,Mapkit,我是Xcode新手,所以如果我的问题很愚蠢,请原谅 我有一个链接到UIAlertView框的注释,该框有两个选项(关闭,指向此处) 第二个按钮应打开apple maps应用程序,并立即为用户提供逐轮导航 现在我的问题是,我的地图上有很多注释,当按下每个注释时,用户必须获得获得导航的选项。因此,我没有固定的MKPlacemark,我需要将按下的注释中的信息传递给MKPlacemark,以便MKMapItem获得所需的标题位置 我的代码是: 将显示UIAlertView的我的注释方法: - (voi

我是Xcode新手,所以如果我的问题很愚蠢,请原谅

我有一个链接到UIAlertView框的注释,该框有两个选项(关闭,指向此处) 第二个按钮应打开apple maps应用程序,并立即为用户提供逐轮导航

现在我的问题是,我的地图上有很多注释,当按下每个注释时,用户必须获得获得导航的选项。因此,我没有固定的MKPlacemark,我需要将按下的注释中的信息传递给MKPlacemark,以便MKMapItem获得所需的标题位置

我的代码是:

将显示UIAlertView的我的注释方法:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
// get reference to the annotation to access its data
VBAnnotation *ann = (VBAnnotation *)view.annotation;
// deselect the button
[self.mapView deselectAnnotation:ann animated:YES];

// display alert view to the information
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ann.title message:ann.info delegate:self cancelButtonTitle:@"close" otherButtonTitles:@"direction to here", nil];
[alert show];
}
以下是我的UIAlertView按钮操作:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"direction to here"])
{        

//now here i tried a fixed coordination, but i need to pass the actual coordination pressed by the UIAlertView
CLLocationCoordinate2D coordinate;
    coordinate.latitude = 24.41351;
    coordinate.longitude = 39.543002;

    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
    MKMapItem *navigation = [[MKMapItem alloc]initWithPlacemark:placemark];
    NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeWalking};
    [navigation openInMapsWithLaunchOptions:options];

}
}
下面是我的注释列表示例

NSMutableArray *annotations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
VBAnnotation *ann;


//Annotations List

// Mecca Pin
location.latitude = MEC_LATITUDE;
location.longitude = MEC_LONGITUDE;
ann = [[VBAnnotation alloc] init];
[ann setCoordinate:location];
ann.title = @"NewHorizons Institute";
ann.subtitle = @"English and computer training center";
[annotations addObject:ann];
[self.mapView addAnnotations:annotations];
当然我有一个叫做VBAnnotation的类


谢谢…

如果我理解正确,您需要记住
VBAnnotation
对象,以便警报视图委托方法可以访问它。您可以在显示警报视图之前使用
objc\u setAssociatedObject()
将对象与警报视图关联,然后在处理用户对警报的响应时使用
objc\u getAssociatedObject()
检索对象

包含有关Obj-C关联对象的详细信息。要导入以获取函数的文件如下所示:

#import <objc/runtime.h>
#导入

如果
VBAnnotation
对象可以用某种数字ID或索引标识,一种更简单的方法是将该ID或索引存储在警报视图的
标记
属性中-
UIAlertView
UIView
的子类,因此继承该属性。

谢谢……我的VBAnnotation对象拥有5个属性://Coordinate//title//subTitle//informations//name,但只有我需要通过的是协调。。。谢谢这篇文章真的很有趣helpful@AliRaslan如果这个答案有助于解决你的问题,那么你接受它就好了。否则,你可以写下自己的答案并接受。对不起:$我是该网站的新手,不知道“接受”按钮:)