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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:17:50+00:00 2026-05-12T17:17:50+00:00

Can anyone give me the example code that I can use to first present

  • 0

Can anyone give me the example code that I can use to first present a modal view controller, then dismiss it? This is what I have been trying:

NSLog(@"%@", blue.modalViewController);
[blue presentModalViewController:red animated:YES];
NSLog(@"%@", blue.modalViewController);
[blue dismissModalViewControllerAnimated:YES];
NSLog(@"%@", blue.modalViewController);

This code is in viewDidLoad (“blue” and “red” are both subclasses of UIViewController). I expect that I will show the red view and then immediately hide it, with some animation. However this piece of code only presents the modal view and does not dismiss it. Any idea? The first log shows “null” while the two other logs show <RedViewController: 0x3d21bf0>

Another point is, if I put this code in applicationDidFinishLaunching: the red view does not appear at all, and all logs get “null”

  • 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-12T17:17:50+00:00Added an answer on May 12, 2026 at 5:17 pm

    First of all, when you put that code in applicationDidFinishLaunching, it might be the case that controllers instantiated from Interface Builder are not yet linked to your application (so “red” and “blue” are still nil).

    But to answer your initial question, what you’re doing wrong is that you’re calling dismissModalViewControllerAnimated: on the wrong controller! It should be like this:

    [blue presentModalViewController:red animated:YES];
    [red dismissModalViewControllerAnimated:YES];
    

    Usually the “red” controller should decide to dismiss himself at some point (maybe when a “cancel” button is clicked). Then the “red” controller could call the method on self:

    [self dismissModalViewControllerAnimated:YES];
    

    If it still doesn’t work, it might have something to do with the fact that the controller is presented in an animation fashion, so you might not be allowed to dismiss the controller so soon after presenting it.

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

Sidebar

Related Questions

Can anyone give me an example of successful non-programmer, 5GL (not that I am
Can anyone give me pointers to good books or web sites that teach how
Can anyone give a concise set of real-world considerations that would drive the choice
I want to print the first 10000 prime numbers. Can anyone give me the
Can anyone give me a complete list of string manipulation function in Microsoft SQL
Can anyone give me details of runtime error 3734 in Access vba. For reference
Can anyone give me a scenario where they think busy cursors are justified? I
Can anyone give me an idea how can we show or embed a YouTube
Can anyone give an idea of how should I implement undo/redo of cutting/copying/pasting of
Are there some help resources, or can anyone give me a brief Idea how

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.