gpt4 book ai didi

iphone - 将用户文本输入添加到 map 注释

转载 作者:行者123 更新时间:2023-11-29 04:43:40 25 4
gpt4 key购买 nike

我有一个简单的应用程序,允许用户标记位置。应用程序中有 2 个按钮,1 个用于清除标签,1 个用于标记位置。

我正在使用嵌入了 UITextfield 的 UIAlertview。我需要从 UITextfield 获取用户输入并将其应用于 map 上的注释。我的标签按钮代码如下

- (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];
}

我尝试了几个选项,有些返回空值,有些则什么也不返回。我正在开始 iOS 开发,只是无法弄清楚这部分

最佳答案

当警报解除时,您需要捕获文本字段的输入。此代码假设您保留新的或编辑的注释的引用。

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
UITextField *textField = [alertView textFieldAtIndex:0];
self.annotationBeingEdited.subtitle = textField.text;
}

关于iphone - 将用户文本输入添加到 map 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9980507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com