使用UIAlertViewStylePlainTextInput编辑注释文本 [英] Edit annotation text with an UIAlertViewStylePlainTextInput
问题描述
我可以将图钉注释放到具有公开按钮的地图上.单击该按钮时,会弹出一个alertView,在其中可以删除所选的注释.我现在尝试使用UIAlertViewStylePlainTextInput编辑选定的注释字幕.关于如何执行此操作的任何想法?
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"Annotation button clicked");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Annotation" message:@"Edit Subtitle" delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Update Subtitle", @"Remove Pin",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"Hide button clicked");
}
if (buttonIndex == 1) {
NSLog(@"Update button clicked");
//e.g. subtitle.text = [[alertView textFieldAtIndex:0] text];
}
if (buttonIndex == 2) {
NSLog(@"Remove button clicked");
[self.map removeAnnotations:self.map.selectedAnnotations];
}
}
就像删除注释一样,您可以使用地图视图的selectedAnnotations
属性来访问所选注释以更新其subtitle
.>
以下示例假定您对注释使用注释类MKPointAnnotation
(具有可设置的subtitle
属性),但可以根据需要将其替换为您的类:
NSLog(@"Update button clicked");
//e.g. subtitle.text = [[alertView textFieldAtIndex:0] text];
//Make sure there is a selected annotation...
if (self.map.selectedAnnotations.count > 0)
{
//Since only one annotation can be selected at a time,
//the selected annotation is the one at index 0...
id<MKAnnotation> ann = [self.map.selectedAnnotations objectAtIndex:0];
//Make sure the selected annotation is one of our types...
if ([ann isKindOfClass:[MKPointAnnotation class]])
{
MKPointAnnotation *pa = (MKPointAnnotation *)ann;
pa.subtitle = [[alertView textFieldAtIndex:0] text];
}
}
I can drop pin annotations onto a map which has a disclosure button. When that button is clicked an alertView pops up in which I can remove the selected annotation. I am now trying the edit the selected annotation subtitle with UIAlertViewStylePlainTextInput. Any ideas on how I can do this?
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"Annotation button clicked");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Annotation" message:@"Edit Subtitle" delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Update Subtitle", @"Remove Pin",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"Hide button clicked");
}
if (buttonIndex == 1) {
NSLog(@"Update button clicked");
//e.g. subtitle.text = [[alertView textFieldAtIndex:0] text];
}
if (buttonIndex == 2) {
NSLog(@"Remove button clicked");
[self.map removeAnnotations:self.map.selectedAnnotations];
}
}
Just like when removing the annotation, you can use the map view's selectedAnnotations
property to get access to the selected annotation to update its subtitle
.
The following example assumes you're using the annotation class MKPointAnnotation
(which has a settable subtitle
property) for your annotations but you can replace it with your class as needed:
NSLog(@"Update button clicked");
//e.g. subtitle.text = [[alertView textFieldAtIndex:0] text];
//Make sure there is a selected annotation...
if (self.map.selectedAnnotations.count > 0)
{
//Since only one annotation can be selected at a time,
//the selected annotation is the one at index 0...
id<MKAnnotation> ann = [self.map.selectedAnnotations objectAtIndex:0];
//Make sure the selected annotation is one of our types...
if ([ann isKindOfClass:[MKPointAnnotation class]])
{
MKPointAnnotation *pa = (MKPointAnnotation *)ann;
pa.subtitle = [[alertView textFieldAtIndex:0] text];
}
}
这篇关于使用UIAlertViewStylePlainTextInput编辑注释文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!