objective-c - 如何在消息框中显示文本框objective-c

标签 objective-c ios5

我想在用户按下主 Storyboard 中的按钮时显示包含标签和文本框的消息框以及确定按钮和取消按钮,并在用户在 IOS 上按确定后获取文本框中的字符串?

我知道如何显示错误消息或类似的内容,但我不知道如何显示这样的消息框?

最佳答案

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Save"
                                                        message:@"Enter File Name"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"OK", nil];

    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

    [alertView show];



- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Alert View dismissed with button at index %d",buttonIndex);

    switch (alertView.alertViewStyle)
    {
        case UIAlertViewStylePlainTextInput:
        {
            UITextField *textField = [alertView textFieldAtIndex:0];
            NSLog(@"Plain text input: %@",textField.text);
        }
            break;

        case UIAlertViewStyleSecureTextInput:
        {
            UITextField *textField = [alertView textFieldAtIndex:0];
            NSLog(@"Secure text input: %@",textField.text);
        }
            break;

        case UIAlertViewStyleLoginAndPasswordInput:
        {
            UITextField *loginField = [alertView textFieldAtIndex:0];
            NSLog(@"Login input: %@",loginField.text);

            UITextField *passwordField = [alertView textFieldAtIndex:1];
            NSLog(@"Password input: %@",passwordField.text);
        }
            break;

        default:
            break;
    }
}

关于objective-c - 如何在消息框中显示文本框objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11128724/

相关文章:

objective-c - Segue 未出现在图像选择器之后

android - 如何在 Android 和 IOS 中创建基本的 Google Glass 应用程序

ios - 处理 Facebook 用户照片的分页

ios - GPSDictionary 返回 nil,uiimage 的元数据中没有 exif 位置数据

iphone - 如何在 iOS 中更改 GPS 更新时间

ios - IOS Native 中的 Worklight Adapter 调用传递 JSON 参数

ios - ACAccountCredential 为 oauthToken 返回 null

objective-c - 为什么当我删除相关对象时,Core Data 会复活已删除的对象?

iphone - 清除 UIImage 上的绘图?

ios - 如何在推文中添加照片库(或相机)的图像?