如何在annotationView上设置按钮以在iPhone中执行操作?
我想在 iphone 的 mapkit 的 commentView 中添加按钮,以便在单击该按钮时执行操作。单击该按钮后如何执行操作?我也无法使用以下代码在注释视图中添加按钮:
- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
谁能告诉我如何将按钮添加到默认用户位置的蓝点注释视图中?提前致谢。
I want to add button in annotationView in mapkit in iphone for performing an action on clicking that button. How can i perform action on clicking that button? i also dont able to add button in annotation view using the following code:
- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Can anyone please tell me how can i add button to the default userlocation's blue dot's annotation view? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我曾经
捕捉按钮按下的情况。
的按钮:
我创建了这样
I used
to capture the button press.
And I created the button like this:
in
只需看看我的代码示例:
希望它能帮助您......
Just look at my code sample :
Hope it helps you...
要在默认蓝点的annotationView中添加按钮,请使用委托方法并按以下方式添加按钮:
For adding the button in default blue dot's annotationView, use the delegate method and add button there in following way: