I have a simple app that will allow a user to tag a location. 2 buttons in the app 1 to clear tags and 1 to tag location.
I have working UIAlertview with UITextfield embedded. I need to take the user input from UITextfield and apply it to annotation on the map. My tag button code is below
- (void) tag
{
MapAnnotation *annotation = [[MapAnnotation alloc] initWithCoordinate:current.coordinate];
NSString *locString = [NSString stringWithFormat:@"%f, %f", current.coordinate.latitude, current.coordinate.longitude];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.timeStyle = NSDateFormatterLongStyle;
//insert UITextfield
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Name your Location" message:nil delegate:self cancelButtonTitle:@"Continue" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeDefault;
alertTextField.placeholder = @"Enter title of your tag";
[alert show];
// I have tried numerous variations of NSString below
//NSString *pintitle = NSLog(@"%@", alertTextField.text);
annotation.title = pintitle;
annotation.subtitle = locString;
[mapView addAnnotation:annotation];
}
i have tried several options some returning a null value and others nothing. I am beginning iOS development and just can’t get this part figured out
You need to catch the input of the text field when the alert is dismissed. This code assumes that your keep a reference of the new or edited annotation.