In meiner App habe ich zwei textFields
, durch Klicken auf jede textField
ich kann Orte laden von Google Orte Autocomplete.In Benutzerhandler ich habe zuweisen, in welchem Textfeld ich das Ergebnis zeigen.Wenn ich klicken Sie auf erstes Textfeld, Der Wert zeigt das zweite Textfeld an. Ich setze Tag-Werte für beide Textfelder. Unten ist mein voller Code. Danke im Voraus.Wie verwende ich Autocomplete mit zwei Textfeldern ios?
//when first textfield clicked
- (IBAction)onLaunchClicked:(id)sender {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
//when second textfield clicked
- (IBAction)to_click:(id)sender {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
//have to set values in correct textfields
if (textfield.tag == 10001){
from_txt.text=place.formattedAddress;
}
else {
to_txt.text= place.formattedAddress;
}
}
Nein, deklariere kein globales. Deklarieren Sie eine Instanzvariable. Es gibt einen großen Unterschied. – rmaddy
@rmaddy Bearbeitete Antwort für die Variable instance. –
Es funktioniert für mich.Thanks @Nirav – Vignesh