【发布时间】:2012-10-11 08:35:05
【问题描述】:
我正在创建一个带有详细信息披露按钮的 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,直到您点击它并出现。
这是我遇到的最奇怪的问题之一。
【问题讨论】:
标签: objective-c uibutton mkannotationview