我在地图iOS6上工作,我遇到了一些麻烦:由于下面的图像,当前位置和placeMark的注释也有callOut按钮,但我需要按钮做不同的任务,我该如何做呢?这意味着在当前位置,我需要callOut按钮来执行此任务,而在placeMark中,callout按钮执行另一项任务。
请访问此页面查看图片
http://upanh.com/listing/?s=c3f4954854a30fe50e3e15f9ae064ba2
我没有足够的声誉在这里张贴这张图片。
我试过这段代码:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure)
{
...
locationSheet.cancelButtonIndex = locationSheet.numberOfButtons - 1;
}else if ([(UIButton*)control buttonType] == UIButtonTypeInfoLight)
{
...
locationSheet.cancelButtonIndex = locationSheet.numberOfButtons - 1;
}
}和
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
// 1
if (buttonIndex != actionSheet.cancelButtonIndex)
{
if (buttonIndex == 0)
{
}
}
}如何在actionSheet中的两个按钮之间执行不同的任务?很难解释我的情况,我希望每个人都能理解我上面的表现,并感谢你们的帮助。谢谢你的预支。
发布于 2013-03-27 02:59:56
我无法获取你的图片--但是如果你有实际的按钮(UIButton)而不是MKAnnotations,那么为什么不为你的按钮指定一个标签(当然,每个按钮都有不同的标签),将它们指向相同的功能,然后根据标签进行区分呢?因此(这可以用于任何按钮,而不仅仅是UIButtonTypeCustom,实际上也可以用于任何UIView -它们都支持tag):
UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
firstButton.tag = 100;
secondButton.tag = 200;
[firstButton addTarget:self selector:@selector(doSomething:)];
[secondButton addTarget:self selector:@selector(doSomething:)];
- (void)doSomething:(id)sender {
UIButton *pressedButton = (UIButton*)sender;
if (pressedButton.tag == 100) {
//First button
}
else if (pressedButton.tag == 200) {
//Second button
}https://stackoverflow.com/questions/15644945
复制相似问题