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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:58:40+00:00 2026-06-12T01:58:40+00:00

I have a view controller called vc0 which is presented like this: [self presentViewController:

  • 0

I have a view controller called vc0 which is presented like this:

[self presentViewController: vc1 animated: YES completion: nil];

And in vc1 I have a button to present another view controller:

[self presentViewController: vc2 animated: YES completion: nil];

Then in vc2, I have a button to dismiss the view controller:

[self dismissViewControllerAnimated:YES completion: ^{
// over here I call one method in vc1
}

And as expected it returns back to vc1.. however there is a button in vc1 to go back to vc0 by dismissing the view controller like this:

    [self dismissViewControllerAnimated:YES completion:nil];

But for some reason it doesn’t work, the view controller does not get dismissed back to vc0. When I first present vc1, I can press the button to dismiss the view controller and it works. But when I press the button to open vc2, and when I dismiss vc2 back to vc1, and THEN I press the button to dismiss the view controller, that is when it doesn’t work.

Sorry if the question is a bit unclear, it is a bit hard to phrase what I am trying to say.

Also one more thing:

I tried replacing dismissViewControllerAnimated: in vc1 to manually present vc0, but then I get a log in the console saying that I am trying to present a vc0 but vc1’s view is not in the window hierarchy. What does this mean?

Thanks for help!

UPDATE:

IN THIS CASE VC0 IS MenuMileIndexViewController – VC1 IS FlightViewController – VC2 IS BookmarksTableViewController

Here is code involved:

MenuMileIndexViewController:

- (IBAction)goToOriginPage {

FlightRecorder *origin = [[FlightRecorder alloc] init];
[self presentViewController:origin animated:YES completion:nil];

}

Flight Recorder:

    - (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar {

        [self bringUpBookmarkkTable];
}

- (void) bringUpBookmarkkTable {

    BookmarkTableViewController *bookmarkTVC = [[BookmarkTableViewController alloc] init];

    [bookmarkTVC setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];

    [self presentViewController:bookmarkTVC animated:YES completion:nil];
}

- (IBAction)cancel {

[self dismissViewControllerAnimated:YES completion:nil];

}

- (void)endBookmarkProcessWithBookmarkCollection: (NSDictionary *)dict {

    presetBookmarkContext = [dict mutableCopy];

    bookmarkMode = YES;

    NSString *compiledText = nil;

    NSNumber *number1 = [NSNumber numberWithInt: 1];

    if ([dict objectForKey: @"bookmarkTag"] == number1) {

        compiledText = [NSString stringWithFormat: @"%@ to %@", [dict objectForKey: @"origin"], [dict objectForKey: @"destination"]];
    }
    else {

        compiledText = [NSString stringWithFormat: @"%@ to %@", [dict objectForKey: @"destination"], [dict objectForKey: @"origin"]];
    }

    compiledText = [compiledText stringByReplacingOccurrencesOfString:@"Origin: " withString:@""];

    compiledText = [compiledText stringByReplacingOccurrencesOfString:@"Destination: " withString:@""];

    flightContext = [NSDictionary dictionaryWithObjectsAndKeys: [dict objectForKey: @"miles"], @"miles", compiledText, @"location", [[NSUserDefaults standardUserDefaults] objectForKey: @"tempD"], @"date", nil];

    NSString *string = [NSString stringWithFormat: @"\nMiles: %.2f\nFlight: %@\nDate: %@", [[dict objectForKey: @"miles"] floatValue], compiledText, [[NSUserDefaults standardUserDefaults] objectForKey:@"tempD"]];

    UIAlertView *bvkBookmarkAlertView = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:string delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];

    [bvkBookmarkAlertView show];
}



 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1) {

        [self cancel]; // Even though cancel is an IBAction, IBAction is the same thing as void so it is callable
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1) {

        [TheMileIndexViewController addDesiredMilesToIndex: [[flightContext objectForKey: @"miles"] doubleValue]];

        [TravelLogViewController addFlight: flightContext];

        if (!bookmarkMode) {

            if ([checkbox isSelected]) {

                [BookmarkHandler uploadBookmark: bookmarkFlightContext];
            }    
        }
    }

    if (buttonIndex == 0) {

        if ([alertView.title isEqualToString: @"Confirmation"]) {

            bookmarkMode = NO;
        }
    }

}

BookmarksTableViewController:

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

    [tableView deselectRowAtIndexPath:indexPath animated: YES];

    NSDictionary *dict = [[BookmarkHandler bookmarkCollection] objectAtIndex: indexPath.row];

    fl = [[FlightRecorder alloc] init];

    [self dismissViewControllerAnimated:YES completion:^{

        [fl endBookmarkProcessWithBookmarkCollection: dict];
    }];
}

NOW, I have created a screen recording of the app in simulator showing what is the problem. I can email that to you for reference. So I can email that to you.

  • 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-12T01:58:41+00:00Added an answer on June 12, 2026 at 1:58 am

    I would recommend to always dismiss a VC from the VC that actually presented it – using a delegate. This is actually also the Apple recommended way – as was pointed out in a previous answer to my question regarding this issue.

    So if you have VC0 presenting VC1, have the dismiss VC1 code in VC0 too, using delegate scheme.

    I have learned that this is the savest way to handle presenting and dismissing – even though sometimes it works to dismiss VC1 within VC1 itself.

    I have asked a very related question, you might be interested to check this too. It shows the code…

    ps I also read that some dismiss only VC1 – which in turn will also dismiss VC2. However, if my previous suggestion works, I would not do this. Sometimes I get information during execution (no crash) that the VC does not exist anymore or anything related to that – so I assumed this is not the best solution. But if my prvious suggestion does not work, you may try the second one.

    Though no guarantee that this will last the updates to new iOS, since this issue keeps hauting me for several iOS updates now :-), so I decided to go the standard recommended route.

    EDIT:
    This is my modified code – it works without problems – however it is not clear what you intend to happen AFTER the user reponds to the Alert and whether the Alert should be on VC1 or VC0. Anyway using delegate and callbacks I do not see any issue. Please explain should I have missed your point…

    FlightViewControllerProtocol.h

    @protocol FlightViewControllerProtocol <NSObject>
    -(void) dismissVCAndEndBookmark;
    @end
    

    FlightViewController.m

    #import "FlightViewController.h"
    #import "FlightViewControllerProtocol.h"
    #import "BookmarksTableViewController.h"
    @interface FlightViewController ()
    
    @end
    
    @implementation FlightViewController
    @synthesize delegate;
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar {
    
        [self bringUpBookmarkkTable];
    }
    
    - (IBAction) bringUpBookmarkkTable {
    
        BookmarksTableViewController *bookmarkTVC = [[BookmarksTableViewController alloc] init];
        bookmarkTVC.delegate = self;
        [bookmarkTVC setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];
    
        [self presentViewController:bookmarkTVC animated:YES completion:nil];
    }
    
    - (IBAction)cancel {
    
        [self dismissViewControllerAnimated:YES completion:nil];
    
    }
    
    - (void)endBookmarkProcessWithBookmarkCollection: (NSDictionary *)dict {
    
    //    presetBookmarkContext = [dict mutableCopy];
    
    //    bookmarkMode = YES;
    
        NSString *compiledText = nil;
    
        NSNumber *number1 = [NSNumber numberWithInt: 1];
    
        if ([dict objectForKey: @"bookmarkTag"] == number1) {
    
            compiledText = @"Text1";
        }
        else {
            compiledText = @"Text2";
        }
    
    
    //    flightContext = [NSDictionary dictionaryWithObjectsAndKeys: [dict objectForKey: @"miles"], @"miles", compiledText, @"location", [[NSUserDefaults standardUserDefaults] objectForKey: @"tempD"], @"date", nil];
    
        NSString *string = compiledText;
    
        UIAlertView *bvkBookmarkAlertView = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:string delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
    
        [bvkBookmarkAlertView show];
    }
    
    
    - (void) dismissVCAndEndBookmark {
        [self dismissViewControllerAnimated:YES completion:nil];
         [self endBookmarkProcessWithBookmarkCollection: nil];
    }
    
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    
        if (buttonIndex == 1) {
    
            [self cancel]; // Even though cancel is an IBAction, IBAction is the same thing as void so it is callable
        }
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        if (buttonIndex == 1) {
    
            NSLog(@"alertView1");
               }
    
        if (buttonIndex == 0) {
            NSLog(@"alertView2");
    
        }
    
    }
    
    @end
    

    BookmarksTableViewController.h

     @interface BookmarksTableViewController : UIViewController
    {
        id delegate;
    }
    
    @property (nonatomic,strong)   id delegate;
    
    @end
    

    BookmarksTableViewController.m

    - (IBAction)goBack {
        [self.delegate dismissVCAndEndBookmark];
    }
    

    Esp the callback in BookmarksTableViewController.m seems to be the main issue in your implementation if I understood your intentions correctly.

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

Sidebar

Related Questions

Let's say I have a view controller called vc1, which a synthesized property called
Ok, so here's the situation. I currently have a view controller called MainViewController which
Hi guys i have controller which returns a partial view, the controller is called
I have a View Controller, called TVOutViewController (.h & .m) which should handle my
I have implemented a view controller with a table view controll called ligatable. This
i have a view Controller called as VegQuantity which does totalcost=(quantity*cost of the dish)
I have a one View Controller Called ThemeViewController with three nibs, all of which
I have a controller called Diary with an action called View . If I
I have a segue (called ToSettingsSegue ) that pushes a custom view controller (
i have view controller which contains a button which show the image library ,if

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.