首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >annotationView中的不同callOut

annotationView中的不同callOut
EN

Stack Overflow用户
提问于 2013-03-27 02:41:59
回答 1查看 58关注 0票数 0

我在地图iOS6上工作,我遇到了一些麻烦:由于下面的图像,当前位置和placeMark的注释也有callOut按钮,但我需要按钮做不同的任务,我该如何做呢?这意味着在当前位置,我需要callOut按钮来执行此任务,而在placeMark中,callout按钮执行另一项任务。

请访问此页面查看图片

http://upanh.com/listing/?s=c3f4954854a30fe50e3e15f9ae064ba2

我没有足够的声誉在这里张贴这张图片。

我试过这段代码:

代码语言:javascript
复制
- (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;
    }
}

代码语言:javascript
复制
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    // 1
    if (buttonIndex != actionSheet.cancelButtonIndex)
    {
        if (buttonIndex == 0)
        {
        }
    }
}

如何在actionSheet中的两个按钮之间执行不同的任务?很难解释我的情况,我希望每个人都能理解我上面的表现,并感谢你们的帮助。谢谢你的预支。

EN

回答 1

Stack Overflow用户

发布于 2013-03-27 02:59:56

我无法获取你的图片--但是如果你有实际的按钮(UIButton)而不是MKAnnotations,那么为什么不为你的按钮指定一个标签(当然,每个按钮都有不同的标签),将它们指向相同的功能,然后根据标签进行区分呢?因此(这可以用于任何按钮,而不仅仅是UIButtonTypeCustom,实际上也可以用于任何UIView -它们都支持tag):

代码语言:javascript
复制
 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
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15644945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档