gpt4 book ai didi

ios - 如何在点击图像时弹出用于输入数据的 UITextField?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:40 26 4
gpt4 key购买 nike

如果我点击一个图像,我可以弹出用于输入数据的 UITextfield 吗?我该怎么做?

最佳答案

您可以按如下方式使用 UIAlertView:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Please enter your text:"
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];

alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeDefault;
textField.placeholder = @"Enter some text";

[alert show];

编辑:处理返回的文本,实现委托(delegate)方法

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex > 0) {
UITextField *textField = [alert textFieldAtIndex:0];
NSString *text = textField.text;
if(text == nil) {
return;
} else {
//do something with text
}
}
}

关于ios - 如何在点击图像时弹出用于输入数据的 UITextField?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10928984/

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