0

Comportement attendu: l'utilisateur clique à l'intérieur TextField1, le clavier apparaît, l'utilisateur entre une valeur, NextButton est pressé, le clavier doit être fermé. Anomalie: le clavier est annulé en appuyant sur NextButton, mais il réapparaît après que les alertes qui suivent soient ignorées! Pourquoi?Rejet erratique du clavier logiciel

D'autre part, si l'alerte est jamais appelé (//[self showDisclaimer]) le clavier se ... correctement rejeté

Je sais que alertView est dépréciée, mais ce n'est pas la source de l'erreur, parce que je reçois exactement le même comportement si j'utilise UIAlertController à la place.

Quelqu'un peut-il nous éclairer à ce sujet?

- (IBAction) NextButton: (id) sender 
{ 
    [self backgroundTouch:id]; //Dismisses the keyboard 
    [self showDisclaimer]; 
} 

- (void) showDisclaimer { 

    UIAlertView *alertView = [[UIAlertView alloc] 
       initWithTitle:@"Disclaimer" message: @"bla bla bla"     
       delegate:self 
       cancelButtonTitle: nil 
       otherButtonTitles:@"Don't agree", @"I AGREE", nil]; 
    [alertView show]; 
} 


- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if([title isEqualToString:@"I AGREE"]) 
    { 
     [self showAlert]; 
    } 
    else if([title isEqualToString:@"Don't agree"]) 
    { 
     //Do something else 
    } 
} 

- (IBAction) backgroundTouch: (id)sender { 

    [TextField1 resignFirstResponder]; 
} 
+0

jeddi fiollow la réponse ci-dessous – user3182143

Répondre

0

Ma réponse est pour vous

ViewController

.h

#import <UIKit/UIKit.h> 
@interface ViewController : UIViewController<UITextFieldDelgate> 
@property (nonatomic, strong) IBOutlet UITextField *txtFld; 
@property (nonatomic, strong) UITextField *currentTxtFld; 
- (IBAction)NextButton:(id)sender; 
@end 

.m

#import "ViewController.h" 
@interface ViewController() 
@end 
@implementation ViewController 
@synthesize currentTxtFld; 
@synthesiz txtFld; 


- (void)viewDidLoad { 
     txtFld.delegate = self; 
} 

- (IBAction) NextButton: (id) sender 
{ 
    [currentTxtFld resignFirstResponder]; 
    [self showDisclaimer];    
} 

- (void) showDisclaimer 
{ 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Disclaimer" message:@"bla bla bla" preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *agreeBtnAction = [UIAlertAction actionWithTitle:@"I AGREE" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ 
     .......//Your code HEre 
    }]; 
    UIAlertAction *dontagreeBtnAction= [UIAlertAction actionWithTitle:@"Don't agree" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ 
     .......//Your code Here 
    }]; 

    [alert addAction:agreeBtnAction]; 
    [alert addAction:dontagreeBtnAction]; 
    [self presentViewController:alert animated:YES completion:nil]; 

} 

#pragma mark - UITextField Delegate methods 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    currentTxtFld = textFld; 
    return YES; 
    } 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
    }