UIAlertController UITextField

来源:互联网 发布:数码宝贝网络侦探存档 编辑:程序博客网 时间:2024/05/16 08:26
-(void)alterUsername{    /**     *  弹出提示框     */    //初始化提示框    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"给自己起个特别的昵称吧!" message:nil preferredStyle:UIAlertControllerStyleAlert];    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {                textField.text = self.lblUsername.text;                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alertTextFieldDidChange:) name:UITextFieldTextDidChangeNotification object:textField];            }];        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action){        NSLog(@"alterUsername");    }]];    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];    [self presentViewController:alert animated:YES completion:nil];}- (void)alertTextFieldDidChange:(NSNotification *)notification{        UIAlertController *alertController = (UIAlertController *)self.presentedViewController;        if (alertController) {                UITextField *login = alertController.textFields.firstObject;                UIAlertAction *okAction = alertController.actions.firstObject;                        for (UIAlertAction *okAction in alertController.actions) {            NSLog(@"%@",okAction);        }                okAction.enabled  = login.text.length >= 1  && login.text.length <= 10;            }    }

0 0
原创粉丝点击