Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3400628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:54:59+00:00 2026-05-18T04:54:59+00:00

I have two views that need to be shown modally, one after the other.

  • 0

I have two views that need to be shown modally, one after the other. This doesn’t work if we dismiss and show consecutively, like this:

[rootController dismissModalViewControllerAnimated: YES];
[rootController presentModalViewController: psvc animated: YES];

The second modal view simply doesn’t show up.

I’ve seen a fix that was something like this:

[rootController dismissModalViewControllerAnimated: YES];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self performSelector: @selector(seekModal) withObject: nil afterDelay: 0.5];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];

The problem is that this won’t work all the time (the delay needed is superior, sometimes).

Another possible fix would be to eliminate the animation:

[rootController dismissModalViewControllerAnimated: NO];
[rootController presentModalViewController: psvc animated: YES];

But I’d really like to keep the animation, to keep the feel that the first modal is out of the way. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:54:59+00:00Added an answer on May 18, 2026 at 4:54 am

    EDIT: The “correct” mechanism to do this in iOS5+ would be to use the – dismissViewControllerAnimated:completion: method, and present the sequential view controller from the completion block.


    The viewcontroller that is being shown modally will have its viewDidDisappear:animated: method called once the modal-dismissal-animation is complete. AFIK this is the only place you can hook to initiate a subsequent presentModalViewController:animated: call.

    I have a class that I use for presenting modal view controllers and it implements the logic you’re looking for via a callback to the presenting view controller once the dismissal is complete. To use this class, simply alloc/init an instance and present using the normal presentViewController:animated: call. Implement the following method on the presenting view controller:

    - (void) modalViewControllerDidDismiss:(UIViewController *)modalViewController
    

    This will be called at once the modal view controller is gone, and you can present a new modal view controller at this time.

    One nice thing too – since this class is a specialization of UINavigationController, you can configure the navigationBar on/off as you like. The class also has built-in logic to show a dismiss button, as you like.

    Here’s the class definition:

    @protocol TSModalViewControllerDelegate
    
    - (void) modalViewControllerDidDismiss: (UIViewController*) modalViewController;
    
    @end
    
    @interface TSModalViewController : UINavigationController 
    {
        UIViewController*   _originalParentViewController;
    }
    @property BOOL dismissButtonHidden;
    
    - (id) initWithViewController: (UIViewController*) vc;
    - (id) initWithClass: (Class) c;
    - (id) initWithClass: (Class) c nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
    
    @end
    

    And the class implementation:

    @implementation TSModalViewController
    @synthesize dismissButtonHidden;
    
    - (id) initWithViewController: (UIViewController *)vc
    {
        return [super initWithRootViewController: vc];
    }
    
    - (id) initWithClass:(Class)c
    {
        UIViewController* vc = [[[c alloc] init] autorelease];
        return [self initWithViewController: vc];
    }
    
    - (id) initWithClass: (Class) c nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        UIViewController* vc = [[[c alloc] initWithNibName:nibNameOrNil bundle:nibBundleOrNil] autorelease];
        return [self initWithViewController: vc];
    }
    
    - (void) viewDidAppear: (BOOL) animated
    {
        [super viewDidAppear: animated];
    
        [_originalParentViewController release];
        _originalParentViewController = [self.parentViewController retain];
    
        if (!self.dismissButtonHidden)
        {
            UIBarButtonItem* dismissButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemStop
                                                                                            target: self 
                                                                                            action: @selector(onDismiss:)] autorelease];
    
            UIViewController* rootViewController = [self.viewControllers objectAtIndex:0];
    
            rootViewController.navigationItem.leftBarButtonItem = dismissButton;
            self.navigationBarHidden = NO;
        }   
    }
    
    - (void) viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear: animated];
        if ( [_originalParentViewController respondsToSelector: @selector(modalViewControllerDidDismiss:)] )
        {
            [_originalParentViewController performSelector: @selector(modalViewControllerDidDismiss:) withObject: self];
        }
    }
    
    - (void) dismissModalViewControllerAnimated:(BOOL)animated
    {
        return [self.parentViewController dismissModalViewControllerAnimated: animated];
    }
    
    - (void) onDismiss: (id) sender
    {
        [self.parentViewController dismissModalViewControllerAnimated: YES];
    }
    
    - (void) didReceiveMemoryWarning 
    {
        [super didReceiveMemoryWarning];
    }
    
    - (void) viewDidUnload 
    {
        [super viewDidUnload];
    }
    
    - (void)dealloc 
    {
        [_originalParentViewController release];
        [super dealloc];
    }
    
    @end
    

    and, here’s how you can use it (in the context of some normal view controller):

    - (void) onShowIt:(id)sender
    {
        TSModalViewController* mvc = [[[TSModalViewController alloc] initWithClass: [MyModalViewController class] nibName: @"MyModalViewController" bundle:nil] autorelease];
        mvc.dismissButtonHidden = YES;  // set to no if you don't want an "automatic" close button
    
        [self presentModalViewController: mvc animated: YES];
    }
    

    and, here is the dismissal callback method, which presents a new modal view controller:

    - (void) modalViewControllerDidDismiss:(UIViewController *)modalViewController
    {
        MyModalViewController* vc = [[[MyModalViewController alloc] initWithNibName: @"MyModalViewController" bundle:nil] autorelease];
        vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
        TSModalViewController* mvc = [[[TSModalViewController alloc] initWithViewController: vc] autorelease];
    
        [self presentModalViewController: mvc animated: YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two views that I would like to combine into one. The first
I have two tabbar items(views) that use the same data, whats the best solution
I have a Delphi 7 application that has two views of a document (e.g.
I have an app that has a centre view with two views off to
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I'm using MVC2 with VS2010 I have a view that has two partial views
I have a UITabBar Application with two views that load large amounts of data
I have a set of views that I need to present in a list-like
I have an asp.net view which has two partial views. One for edit information
I have two view controllers that allow changes to the Address Book. The first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.