【问题标题】:UITextfield is not getting added in UIAlertControllerUITextfield 没有被添加到 UIAlertController
【发布时间】:2017-10-25 07:43:37
【问题描述】:

UITextfield 没有被添加到 UIAlertController 中

这是我的代码:

if ([UIAlertController class]) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Forgot Password" message:nil preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){[![enter image description here][1]][1]
                NSString *str = @"OK Pressed";
            }];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
                NSString *str = @"otherAction Pressed";
            }];
            [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                textField.placeholder = @"placeHolderText";
                textField.keyboardType = UIKeyboardTypeDefault;
            }];
            [alert addAction:okAction];
            [alert addAction:cancelAction];
            [self presentViewController:alert animated:YES completion:nil];
        }

【问题讨论】:

  • 也许这个链接可以帮助你stackoverflow.com/questions/33996443/…Goodluck :)
  • 您尝试过留言吗?
  • 是的,我用@""试过了
  • @GökhanAydın 我也试过了。没有成功。
  • 你可以分享你使用的完整方法吗?

标签: objective-c iphone xcode9


【解决方案1】:

我刚刚试过你的代码,它工作正常。

问题可能出在您调用此代码的地方。例如,它必须在viewDidAppear 中调用,而不是在viewDidLoad 中。

【讨论】:

  • 我已经在用户点击操作上实现了这个,除了显示一个文本字段外,一切都很好
  • 不要发表评论作为答案。
猜你喜欢
  • 1970-01-01
  • 2021-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
相关资源
最近更新 更多