Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 error Warning: Attempt to dismiss from view controller <UINavigationController: 0x1568db40> while a presentation or dismiss is in progress

I have issue in iOS 7 that does not appear in iOS 6.

I have a navigation controller that is displaying another navigation controller to add an employee. This second controller is being presented modally. When I dismiss the second controller either with a "Cancel" or "Done" button, I get an error. Here is the error:

QuickSchedule[880:60b] Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

I am using an unwind segue and dismissing from the first controller using the following relevant code.

This is in ScheduleViewController.m (My main controller window)

- (IBAction)done:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"DoneEditing"]) {
        [[MyManager sharedManager] saveChanges];
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

The connection in the connection inspector for the "Done" button is simply "action -> [unwind done:]"

I had no errors before upgrading to Xcode 5. This all started after upgrading Xcode and my storyboard to iOS 7.

I am getting same error in different spot in my app, but again, it's with a modally presented view controller.

I go from EmployeeViewController to AddEmployeeViewController modally. I get the error again when I return from AddEmployeeViewController.

EmployeeViewController.m

- (IBAction)done:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"ReturnInput"]) {
        AddEmployeeViewController *addController = [segue sourceViewController];
        if (addController.employee) {
            [[MyManager sharedManager] saveChanges];
            [[self tableView] reloadData];
        }
        if (![self.presentedViewController isBeingDismissed]) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
}

- (IBAction)cancel:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"CancelInput"]) {
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

Here is AddEmployeeViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ReturnInput"]) {
        if ([self.firstNameField.text length] || [self.lastNameField.text length]) {

            Employee *newEmployee = [[MyManager sharedManager] createEmployeeWithFirstName:self.firstNameField.text andLastName:self.lastNameField.text];
            [[MyManager sharedManager] addEmployeeToList:newEmployee];
            self.employee = newEmployee;
        }
    }
}

I am still learning, and I have looked for hours online and cannot find an answer to this. I have tried putting the "saving code" in a completion block. I put it back and tried using nil instead of NULL in the completion block argument. As you can see, I have nil in one spot on a completion block argument and NULL on another. No matter what, the error keeps appearing.

Everything works as far a functionality, I just get this error logged to the console. Any help is greatly appreciated.

Note: I do not get this error with regular pushed navigation controllers. This is only happening on dismissing modally presented view controllers.

like image 981
Darrell Avatar asked Dec 02 '22 21:12

Darrell


1 Answers

I'm surprised that you wouldn't see this same problem in previous versions of Xcode, because I think your problem is calling dismissViewControllerAnimated:completion: in the "done" method. This should have been a problem in iOS 6 as well. The unwind segue does the dismissal for you, so you shouldn't call this method yourself. Try commenting it out, and see if that fixes the problem.

like image 173
rdelmar Avatar answered Dec 11 '22 11:12

rdelmar