-1

I am receiving 2 errors while a dismissal is happening in my app.
Warning: Attempt to dismiss from view controller <MyNavigationController> while a presentation or dismiss is in progress!
&
Unbalanced calls to begin/end appearance transitions for <MainViewController>.

I've searched around and everywhere says that there is usually a conflicting dismissal happening where a button is calling the transition both programmatically and through the storyboard. I, however, am receiving these errors when using the normal back button that comes with nav controllers. I don't do anything with the button at all.

The only thing I can link to the errors is that my nav controller is autorotating while trying to dismiss the view controller. If I remove autorotate or set the orientation of both view controllers to be the same then I don't get the error. Problem is, I need one of the view controllers to be portrait and the other to be landscape...

This is how I set the orientation

NavController.m:

- (NSUInteger)supportedInterfaceOrientations {
    return self.topViewController.supportedInterfaceOrientations;
}

- (BOOL)shouldAutorotate {
    return YES;
}

MainViewController.m:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

OtherViewController.m:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}

I've noticed that for some reason it doesn't autorotate when going to my "OtherViewController", but it apparently tries to autorotate while returning to the "MainViewController", thus causing the crash.

Since it may be relevant, this is how I load my OtherViewController:

[self performSegueWithIdentifier:titles[indexPath.row] sender:nil];

I have a CollectionViewController that calls a push segue I have set up in the storyboard. Titles is an NSArray of the different segue titles connected to the MainViewController.

Here is the flow of what's going on in my app:

MainViewController  : LoadView
MainViewController  : ViewWillAppear
MainViewController  : ViewDidAppear
//This is where I choose to load the OtherViewController
OtherViewController : LoadView
MainViewController  : ViewWillDisappear
OtherViewController : ViewWillAppear
MainViewController  : ViewDidDisappear
OtherViewController : ViewDidAppear
//This is where I select the "Back" button
Warning: Attempt to dismiss from view controller NavController while a presentation or dismiss is in progress!
Unbalanced calls to begin/end appearance transitions for MainViewController.
MainViewController  : ViewWillDisappear
MainViewController  : ViewDidDisappear
Ponyboy47
  • 924
  • 9
  • 15

2 Answers2

0

For a detailed analysis we need more code, especially where the view controller is dismissed.

As for your error message the dismissal call, whichever you use, is called in the middle of some other workflow of showing or dismissing a view controller. That could be when you present or dismiss a modal view controller or when you push or pop one on the navigation stack in

  • loadView
  • viewDidLoad
  • viewWillAppear
  • viewDidAppear
  • viewWillDisappear
  • viewDidDisappear

This list is certainly incomplete but that should be the most common methods that are called within the process.

So share some more code with us.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • I threw comments into everything you suggested and it appears that my log output in ViewDidDisappear never gets logged. So my OtherViewController isn't even being told to disappear... ViewWillAppear and LoadView are not called on my MainViewController either – Ponyboy47 Jun 22 '14 at 17:13
  • I did notice something strange. After receiving the two errors, the MainViewControllers calls both ViewWillDisappear and ViewDidDisappear.. – Ponyboy47 Jun 22 '14 at 17:58
  • There is nothing strange with ...With... and ...Did... beeing called. It is rahter a matter of sequence and you can make use of that. – Hermann Klecker Jun 22 '14 at 22:20
0

Without getting into too much details, you need to find a way to do one after the other. The tricky part is that there is no delegate that tells you when a view was dismissed after a segue. However, after a segue, when viewWillAppear is called, the previous view was dismissed. Maybe try to rotate the view from the code, and do so in the viewWillAppear?

bauerMusic
  • 5,470
  • 5
  • 38
  • 53
  • The only way I've been able to force rotation is via [this answer](http://stackoverflow.com/questions/19095161/force-landscape-ios-7) tweaked a bit to work like what [this person did](http://stackoverflow.com/questions/19507456/sudzc-arc-version-objc-msgsend-call-causes-exc-bad-access-using-64-bit-archite), but all this did was make autorotate work when going to my OtherViewController. It still has the same crash when returning to my MainViewController – Ponyboy47 Jun 22 '14 at 17:33