Orientation failed after calling setViewControllers: animated:

For some time I came across this (somewhat) random error and cannot understand the problem. Context: I am creating an iPad UISplitView application that has a UINavigationController inside the main view:

Main menu in red, submenu in green and main content in purple The main menu is in red, the submenu is green and the main content is in purple.

This UINavigationController does not fill the entire main view, because I need space for the vertical menu. When the user selects a button in the vertical side menu, he sets up something new for the UINavigationController to show the UITableView with parameters. What do I do with every menu selection:

[self.subMenu setViewControllers:@[subMenuViewController] animated:YES]; 

What happens is that I don’t need to save the menu history, so every time I install a new root view controller in subMenu.

The problem is that I'm starting to mess with the orientation of the device. It does not have a clear picture, but sometimes when I turn, my application crashes. Now, when I run it with tools, this is what I get:

 167 Zombie -1 00:32.101.527 UIKit -[UITableView _spacingForExtraSeparators] 

And interestingly, bad access happens on the previous subMenu root view controller. Therefore, if I click "Events" and then click "Podcasts", bad access occurs when I try to access the "EventsViewController".

So, I assume that something is wrong on my way to replace the subMenu UINavigationController root view controller, but I'm not sure what it is. Maybe I need to make sure that the current root view controller is released before installing a new one?

Any help is much appreciated. :)

+6
source share
2 answers

So first you have to implement the willRotateToInterfaceOrientation , willAnimateToInterfaceOrientation and didRotateToInterfaceOrientation (check the actual signature of these methods) in your view controllers containing a UITableView .

In each of these methods, check the presentation of the DataSource table and the delegate. I think this failure is caused by the release of a delegate or table data source.

You should also check which delgate / datasource table methods call during rotation.

Lastly, make sure that you discard old instances of subMenuViewController and that they are correctly removed from the parent view controller.

+2
source

This is not an unusual failure in the system library code due to the fact that you did not configure it correctly. Your UIWindow, UIApplicationMain, or its view of the content, or your view manager instance, may not have been saved or released in some way.

This torotate method will not help if your controller does not exist yet.

This means which object was released.

For particularly complex problems, you can add the release, save, and dealloc methods (this log and the super call) to your suspicious class and see what frees it. Record -retaincount for tracking (I use this for diagnostic purposes only)

Or you can try this, set a breakpoint at - [UIDevice setOrientation:] and execute your code in the debugger.

To facilitate debugging, you can type call (void) instrumentObjcMessageSends (YES) directly in the debugger console to start recording objc_msgSends in / tmp /, then continue execution and trace all sent messages until the crash.

+4
source

Source: https://habr.com/ru/post/957826/


All Articles