iPhone - Dismissing previous ModalViewControllerAnimated:YES then poping a new ModalViewControllerAnimated:YES - fail

StackOverflow https://stackoverflow.com/questions/4788131

Question

I have a main window that pops a modal view controller. When done in this modal view controller, it returns to the main window then dismisses itself. Then the main windows pops a new Modal view controller with animated=YES.

The problem is that the dismiss call that is done inside the first modalviewcontroller applies to both and SecondController is never shown.

Putting the first dismiss before or after the parent call does not change anything. If first dismiss is set wih animate= NO, everything works fine. But I need the animation.

Main.m

- (void) entry {

    FirstController *nextWindow = [[FirstController alloc] initWithNibName:@"theNIB" bundle:nil];

    nextWindow.caller = self;

    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];

    [self.navigationController presentModalViewController:navController animated:YES];

    [nextWindow release];
    [navController release];
}


- (void) thingsDoneInFirstModalController:(OBJECT)returnValue retval2:(OBJECT2)returnValue2 {
    [self display2ndController];
}

- (void) display2ndController {

    SecondController *nextWindow;

    nextWindow = [[SecondController alloc] initWithNibName:@"NIB2" bundle:nil];

    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
    [self.navigationController presentModalViewController:navController animated:YES];
    [navController release];
    [nextWindow release];
}

1st ModalViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [self.navigationController dismissModalViewControllerAnimated:YES];
    [self.caller thingsDoneInFirstModalController:theResult retval2:someMoreResult];
}

What may I do ? I don't want to catch anything in view....Disapear...

Why does the dismiss colides as they are not called from the same navigation controller ?

Was it helpful?

Solution

The reason is likely the animation when you dismiss it. Try showing the second modal window using the performSelector:withObject:afterDelay:, a method inherited from NSObject. Reference here.

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