【问题标题】:Replace detailDisclosureButton in rightCalloutAccessoryView with customButton in MKAnnotation in Objective-C用 Objective-C 中 MKAnnotation 中的 customButton 替换 rightCalloutAccessoryView 中的 detailDisclosureButton
【发布时间】:2019-05-04 22:59:56
【问题描述】:

我正在尝试在 MKAnnotationView 的 rightcalloutAccessoryView 中显示自定义图像来代替公开按钮,但它没有出现:

这是我的代码:

    UIButton *rightButton = [UIButton new];
    UIImage * rightImage = [UIImage imageNamed:@"blue-car"];

    [rightButton setImage:rightImage forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;

当我执行上述操作时,没有图像出现,如果你点击什么也不会发生。

但是,如果我使用以下细节 disolosureButton,图像确实会出现并且标注是可点击的。

annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

我的自定义按钮代码中缺少什么会阻止按钮出现或执行任何操作?

【问题讨论】:

    标签: ios objective-c uibutton mkannotationview


    【解决方案1】:

    在您的 MKAnnotationView 子类中,您可以简单地提供如下视图:

    - (UIView*) rightCalloutAccessoryView {
        UIView *aView = [[UIView alloc] initWithFrame:yourFrame];
    
        // configure your view as you like...
    
    
        return aView;
    }
    

    您的代码中缺少什么?可能是一个动作,例如

    [rightButton addTarget:nil action:@selector(showDetailCallout:) forControlEvents:UIControlEventTouchUpInside];
    

    此代码将起作用,因为 nil 目标将使 ios 搜索合适的目标(这里是 mapView 委托)

    实际上根据文档,您的代码应该可以工作(因为 UIButton 是 UIControl 的子类,应该调用 mapView 委托的 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多