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 8085725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:13:13+00:00 2026-06-05T18:13:13+00:00

Background: I would like to dismiss a modalView that I have presented earlier and

  • 0

Background: I would like to dismiss a modalView that I have presented earlier and right away present the same viewController that I just dismissed with new information.

Problem: I have not been very successful in doing so without an explicit pointer to the parent ViewController that presented the first ViewController modally. I am trying to write this class that works without messing around with the previous viewController‘s code.

Possible lead: There are couple of things I have been experimenting with:

1.) Trying to get access to the parent ViewController, which at this time I don’t know how to.

2.) Once access to the parent is gained, I can simply apply the following code:

UIViewController* toPresentViewController = [[UIViewController alloc] init];
    [self dismissViewControllerAnimated:YES completion:^{
        [parentViewControllerAccessor presentModalViewController:toPresentViewController animated:YES];
}];

In theory this should work given the access to parent viewController. I am open to other ways of doing this.

Assumption: You do not have permission to change any code in the parent ViewController.

  • 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-06-05T18:13:15+00:00Added an answer on June 5, 2026 at 6:13 pm

    Your code looks like it should work. If you are using iOS 5 there is a UIViewController property called presentingViewController.

    @property(nonatomic, readonly) UIViewController *presentingViewController;
    

    So you can use this property to get the view controller that presented your modal controller.

    Note: In iOS 4 parentViewController would be set to the presenting controller, so if you are supporting both iOS 4 and 5 you will have to check the OS version first to decide which property to access. In iOS 5 Apple have fixed this so that parentViewController is now exclusively used for the parent of contained view controllers (see the section on Implementing a Container View Controller in the UIViewController documentation).

    Edit: Regarding accessing self.presentingViewController from within the block: By the time the block is called (after the modal view controller is dismissed) the presentingViewController property may get set to nil. Remember that self.presentingViewController inside the block gives the value of the property when the block is executed, not when it was created. To protect against this do the following:

    UIViewController* toPresentViewController = [[UIViewController alloc] init];
    UIViewController* presentingViewController = self.presentingViewController;
    [self dismissViewControllerAnimated:YES completion:^
    {
        [presentingViewController presentModalViewController:toPresentViewController animated:YES];
    }];
    

    This is necessary not because self is gone/dismissed (it is safely retained by the block), but because it is no longer presented, therefore its presentingViewController is now nil. It is not necessary to store the presentingViewController anywhere else, the local variable is fine because it will be retained by the block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header background that I would like to bleed indefinitely on the
I have a background that I would like to change depending on which browser
I have a background task I would like to handle. The thing is that
BACKGROUND: I would like to have small labels in columns of a table. I'm
For my Android app I would like background music. It doesn't have to go
I have a UIWebView with a black background and I would like the phone
I would like to have one background thread which will copy the files through
I have a text field entry in my view that I would like to
I have an icon that I would like to display in an arbitrary hexadecimal
I have a background operation I would like to occur every 20 seconds in

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.