我用一些文本框和兩個按鈕製作UIAlertController。我有按鈕註冊。當我點擊按鈕註冊時如何保持UIAlertController。因爲我在按鈕中運行一些方法後,我的UIAlertController關閉。點擊按鈕註冊後,請幫我保留UIAlertController。我如何驗證UIAlertController中的textfield?單擊按鈕時如何保持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];
請幫幫我!謝謝!
這看起來像一個[XY問題](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。警報的目的是提供快速的交互或信息。爲什麼你需要一個不會消失的警報? – Arc676
因爲當我輸入錯誤的數據,我點擊按鈕註冊我的UIAlertController將關閉。所以我想保持UIAlertController並顯示驗證錯誤,當我輸入錯誤的數據。 –
a)您可能需要一個單獨的窗口。您可以使用界面生成器b)或者,您可以隨時顯示另一個警報 – Arc676