我使用一些文本字段和两个按钮制作UIAlertController。我有按钮注册。单击按钮注册时如何保持UIAlertController。因为我在按钮中运行了一些方法后,我的UIAlertController关闭了。点击按钮注册后请帮我保留UIAlertController。我如何在UIAlertController中验证文本字段?
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Login"
message: @"Input username and password"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"username";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.text=username;
textField.userInteractionEnabled = NO;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"email";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.text=email;
textField.userInteractionEnabled = NO;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"tell";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"address";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"city";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"national";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"postcode";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
n++;
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
[sender setTitle:@"Login with facebook" forState:UIControlStateNormal];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Register" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSArray * textfields = alertController.textFields;
UITextField * usernamefield = textfields[0];
UITextField * emailfield = textfields[1];
UITextField * tellfield = textfields[2];
UITextField * addressfield = textfields[3];
UITextField * cityfield = textfields[4];
UITextField * nationalfield = textfields[5];
UITextField * postcodefield = textfields[6];
//NSLog(@"%@:%@:%@:%@:%@:%@",usernamefield.text,emailfield.text,tellfield.text,
// addressfield.text,cityfield.text,nationalfield.text,postcodefield.text);
NSInteger success=0;
}]];
[self presentViewController:alertController animated:YES completion:nil];
请帮帮我!谢谢!
答案 0 :(得分:2)
默认情况下不可能。由于默认行为会在操作按钮上单击警报控制器。
根据您的需要,您应该使用tableview或自定义视图来管理注册。
显示包含文本字段和按钮或表视图的自定义视图以实现此目的
Alert controller
不适用于此类任务。它仅代表alertview
或actionsheet
,并且两者的默认行为都是在点击时解除。
Alert controller
或alertview
不同, actionsheet
没有任何委托方法。所以使用警报控制器很难管理它。
然后,如果您只想使用警报控制器,那么您可以从其操作的完成处理程序中显示另一个控制器。
您应该保留以前填充的文本字段的记录,以便再次显示在警报控制器上。
希望这会有所帮助:)
答案 1 :(得分:0)
是的,您无法更改Alertcontroller的默认行为。要么必须使用View for Register,要么必须从操作中提出另一个警报。