-(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;
}
}
UIAlertController UITextField
最新推荐文章于 2023-05-29 21:08:26 发布