我正在创建一个带有详细信息披露按钮的 MKAnnotationView。
在 mapView: viewForAnnotation: 我只是创建了一个占位符按钮。
// the right accessory view needs to be a disclosure button ready to bring up the photo
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
在mapView:didSelectAnnotationView:我实际上创建了一个要使用的按钮(带有相关标签)
// create a button for the callout
UIButton *disclosure = [self.delegate mapController:self buttonForAnnotation:aView.annotation];
NSLog(@"DisclosureButton: %@", disclosure);
// set the button's target for when it is tapped upon
[disclosure addTarget:self.delegate action:@selector(presentAnnotationPhoto:) forControlEvents:UIControlEventTouchUpInside];
// make the button the right callout accessory view
aView.rightCalloutAccessoryView = disclosure;
在日志中,该按钮似乎已完全实例化并设置了正确的标签。
这是按钮创建者:
/**
* returns an button for a specific annotation
*
* @param sender the map controller which is sending this method to us (its' delegate)
* @param annotation the annotation we need to create a button for
*/
- (UIButton *)mapController:(MapController *) sender
buttonForAnnotation:(id <MKAnnotation>) annotation
{
// get the annotation as a flickr photo annotation
FlickrPhotoAnnotation *fpa = (FlickrPhotoAnnotation *)annotation;
// create a disclosure button used for showing photo in callout
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// associate the correct photo with the button
disclosureButton.tag = [self.photoList indexOfObject:fpa.photo];
return disclosureButton;
}
当我选择注释时,问题就来了。在选择注释并点击详细信息披露按钮的几秒钟内,没有任何反应。然而,在点击并返回注释几次并测试按钮后,它最终按预期工作。
奇怪的延迟是怎么回事?有时当按钮开始工作时,它只是看起来好像 alpha 设置为 0.0,直到您点击它并出现。
严重的是我遇到的更奇怪的问题之一。