-(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];
}
UIAlertController UITextField
最新推荐文章于 2020-06-18 13:04:59 发布
本文展示了如何使用UIAlertController创建一个包含UITextField的提示框,并监听UITextField的文本变化,实现实时输入验证,确保用户名长度在1到10个字符之间。
摘要由CSDN通过智能技术生成