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

标签 ios popup uitextfield

如果我点击图像,我可以弹出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/

相关文章:

ios - Apple 应用内购买收据验证

ios - iOS:检测文件编码的最佳方法是什么

javascript - 如何制作图像映射弹出窗口

javascript - 在传单弹出窗口中插入 NVD3 图表

javascript - 检测使用 window.open 打开的窗口的 onload 事件

ios - 限制 iOS 上的文本输入边界

ios - Swift - 在 UITableView 中组合 UITextfield

ios - 从一个 View Controller 访问 CLLocationManager 变量到另一个 View Controller

ios - UITextField 委托(delegate)跳转到 100% CPU 使用率并在使用键盘快捷键时崩溃

ios - 如何将图像设置为 UISearchBar 的范围栏项目?