ios - 如何根据uitextfield的tag id获取uitextfield中的值。?
<p><p>我正在使用 <code>GMSAutocompleteViewController</code>,其中我的 <code>uiviewcontroller</code> 中有三个 <code>UITextfield</code>。当第一个 <code>UItextfield</code> 单击时,我将移动到带有标签号的 <code>GMSAutocompleteViewController</code>,但现在我想在 <code>gmsautocompleteviewcontroller</code> 中由用户单击的文本字段中显示地名> 方法。请看我的代码。</p>
<pre><code> - (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"start editing");
if (textField.tag ==1) {
NSLog(@"first");
GMSAutocompleteViewController *acController = [ init];
acController.delegate = self;
;
}
else if (textField.tag ==2)
{
NSLog(@"second");
GMSAutocompleteViewController *acController = [ init];
acController.delegate = self;
;
}
else if (textField.tag ==3)
{
NSLog(@"third");
GMSAutocompleteViewController *acController = [ init];
acController.delegate = self;
;
}
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
NSLog(@"lat and log%f", place.coordinate.latitude);
NSLog(@"lang %f", place.coordinate.longitude);
value = place.name;
;
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
// TODO: handle the error.
NSLog(@"error: %ld", (long));
;
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
NSLog(@"Autocomplete was cancelled.");
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>全局声明一个文本字段</p>
<pre><code> UITextField *tappedTextField;
</code></pre>
<p>检查下面的代码</p>
<pre><code>- (void)textFieldDidBeginEditing:(UITextField *)textField{
tappedTextField = textField;
}
//gmsautocomplete delegate
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
NSLog(@"lat and log%f", place.coordinate.latitude);
NSLog(@"lang %f", place.coordinate.longitude);
tappedTextField.text = place.name;
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何根据uitextfield的tag id获取uitextfield中的值。?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36996928/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36996928/
</a>
</p>
页:
[1]