iOS 编辑 Uialertview 的 TextField

标签 ios objective-c xcode uialertview

代码:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Name your Search" message:@"Save Search as" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil] ;
                alertView.tag = 20;
                alertView.delegate = self;
                alertView.cancelButtonIndex = 1;
                alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
                [alertView show];

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    if(alertView.tag == 20){
        UITextField *textField = [alertView textFieldAtIndex:0];
        textField.text = @"testing";
        if ([textField.text length] == 0){
            return NO;
        }
    }
     return YES;  
}

我创建了一个带有 TEXTINPUT 模式的 UIALERVIEW。我确实在文本框中设置了文本值。它不允许我在出现警报 View 时编辑文本字段值。我的代码有什么问题?提前致谢

最佳答案

添加这一行:textField.userInteractionEnabled = YES;

在这一行之后:textField.text = @"testing";

关于iOS 编辑 Uialertview 的 TextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29863859/

相关文章:

ios - 如何在 Xcode 中为我的 Today Widget 设置图标?

ios - Xcode 6 3.5英寸屏幕截图

objective-c - 使用 respondsToSelector 时抑制 "' …' is deprecated"

ios - ReactiveSwift/ReactiveCocoa : How to use UIButton disabled styling but not when Action is in progress?

ios - 多个导航 Controller

iphone - 在iOS中创建登录功能和搜索功能

objective-c - 是否可以制作没有圆边的 UITextField?

ios - Xcode 7.3 操作无法完成(LaunchServicesError 错误 0)

iphone - 创建 Facebook 应用程序时遇到的问题

iOS 与 Swift 的 String .isEmpty 的兼容性