Search code examples
iosobjective-cpresentviewcontroller

iOS - Present View controller immediately after dismissing an other view controller


I have three View Controller VC1,VC2 and VC3.

VC2 is of a 3rd party library and it is presented on VC1.

Then VC2 dismissed itself and send a callback to VC1 and VC1 try to present VC3 on itself but failed.

Is there some way to present VC3 immediately after dismissing VC2 ?

-(void)onDismisLoginVC{

    MessageVC *messageVC = [[MessageVC alloc] initWithNibName:@"MessageVC" bundle:nil];
    [self.navigationController presentViewController:messageVC animated:YES completion:NULL];

}

Unfortunately I can not use ^completion block of dismissing presented viewcontroller in VC2 because I am just receiving a callback to this method and can't edit code of VC2.


Solution

  • I know we all always put nil for the completion block... but it actually does have some use. I assure you.

    [self dismissViewControllerAnimated:YES completion:^{
        //code to be executed with the dismissal is completed
        // for example, presenting a vc or performing a segue
        }];