Question

I´m presenting a view this way:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ContractDetailsViewController *contractDetailsViewController = [[ContractDetailsViewController alloc] init];
    contractDetailsViewController.client = self.client;
    contractDetailsViewController.contractId = [NSString stringWithFormat:@"%d", indexPath.row];

    [self presentViewController:[[UINavigationController alloc]initWithRootViewController:contractDetailsViewController] animated:YES completion:^{
    }];
}

After the view appears i dismiss it with:

- (void)close
{
    [self dismissViewControllerAnimated:YES completion:^{}];
}

The bug is that the view disappears, the view that was behind it also disappears right after.

Was it helpful?

Solution

This could explain what is happening to your view controllers:

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

(source)

This means that if you present view controller A, then view controller B, then call dismiss on view controller B, both view controllers are dismissed (although only B with an animation).

If you want to manage two different hierarchies of view controllers, you could use a second navigation controller. That means, e.g., that you would present a new navigation controller instead of view controller A, and make view controller A the navigation controller's root controller. Then you would push/pop any other required view controller (B, etc.)

OTHER TIPS

As per apple documentation.

If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to achieve that functionality, just add UIViews in current view and show them in modal way. You can remove them one by one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top