Question

I'm having an issue with my save button in a modal UINavController. When I press the save button, I'm dismissing the keyboard if it is still up, validating the data from the text fields, then showing a UIProgressView while I send my info out.

My problem is that the keyboard isn't getting out of the way fast enough, so keyboard is still up when it is time to show the UIProgressView and it is getting added towards the bottom of my view and it looks stupid.

I can hit the return key, and the keyboard drops, then press save, no issues. But if the user skips the keyboard return key and goes right for the top right save button, I have issues.

Ideally I'd like to implement a short wait statement for it to drop out of sight. Or perform my validation after a delay, but nothing I have tried is working. Please help.

Code Example:

// end edit mode - should kill all keyboards
[[self.tableView superview] endEditing:YES]; 

// make sure everything is entered correctly and validates
[self validateEntryFields]; // keyboard not gone when this finishes

if (valid) { // progress view shows up towards bottom of view
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.delegate = self;
    HUD.labelText = @"Adding User";
    HUD.detailsLabelText = @"Please Wait";
    [HUD showWhileExecuting:@selector(sendNewUserInformation) onTarget:self withObject:nil animated:YES];
}
Was it helpful?

Solution

You may use keyboard notification (it would be more correct solution than based on timer):

[notificationCenter addObserver: self selector: @selector(keyboardDidHide:) name: UIKeyboardDidHideNotification object: nil];

And show your progress view in keyboardDidHide: method.

OTHER TIPS

If a small delay would be working you could try the following code between your validation and your if statement where you decide whether or not you will showing the progress view.

You can use the NSTimer object:

[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(mumboJumbo:)userInfo:nil repeats:NO];

And add your code into a method like:

-(void)mumboJumbo:(id)sender{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.delegate = self;
    HUD.labelText = @"Adding User";
    HUD.detailsLabelText = @"Please Wait";
    [HUD showWhileExecuting:@selector(sendNewUserInformation) onTarget:self withObject:nil animated:YES];
}

If I understood correctly your problem that should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top