UIAlertView + UITextView

UIAlertView + UITextView

我正在寻求帮助。我需要知道如何在 UIAlertView 上实现多行文本输入。我不想使用具有单行输入的 UITextField。

在 UIAlertViews 被弃用之前,我曾经用这样的方式来做到这一点:

    -(IBAction)addComment:(id)sender
{
    //multiline comments
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Export"
                                                        message:@"Save this report to the feed with a comment?"
                                                       delegate:self
                                              cancelButtonTitle:@"No"
                                              otherButtonTitles:@"Yes", nil];

    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextView *textView = [UITextView new];
    [alertView setValue: textView forKey:@"accessoryView"];
    alertView.tag = 3;
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //Check for confirmation on exporting.
    if (alertView.tag == 3) {
        UITextView *textView = [UITextView new];
        [alertView setValue: textView forKey:@"accessoryView"];
        if (buttonIndex == 1)[self writeData:textView.text];
    }
}

iOS8+ 这似乎对我不起作用,来自 textView 的数据总是空的。

I need to know how to achieve multiline text input on a UIAlertView

你不知道。如果你需要的不仅仅是一个内置的 UIAlertView 给你的东西,制作你自己的呈现的视图控制器 看起来 行为 像一个 UIAlertView,除了视图是您的视图,您可以根据自己的喜好对其进行自定义。