The UISplitViewController is the flagship iPad user interface element, as it allows your application to optimize the use of the large screen. This control manages 2 views, usually a master view (for navigation) and a detail view (for content). When in landscape mode, the controller shows both views side-by-side, and when the device is rotated to portrait mode, the master view is hidden and the detail view occupies the full screen. In this case, the SplitView controller places the master view in a hidden UIPopoverController, and the common MO is to add a button to a toolbar on the detail view so the user can call up the hidden master view for navigation – when in landscape this toolbar button is unnecessary (because the view is already showing) and should be hidden.
When testing the forthcoming Falafel 2 Go iPad version, I sometimes encountered a case where after the rotation back to portrait the toolbar button was missing. This is a pretty bad user experience because now the user is looking at detail view content, with no way to navigate – aside from rotating the device again. Of course I looked at my code first, and all seemed ok:
[toolbar setItems:items animated:YES];
This should correctly set the item back on the UIToolbar inside of the splitViewController:willHideViewController:withButtonBarItem:forPopoverController: delegate method.
After discovering that I could easily reproduce this problem by starting in portrait, rotating the device 45 degrees until the view started to change, and then quickly rotating back to portrait - I then tried I the simple Xcode template for a UISplitViewController project. The issue still reproduced, even with only the Apple code. I only found 1 reference to this issue anywhere on the internet (in the Apple forums), confirming my issue, and saying that a bug had been logged with Apple – but no solution. I guess I was able to discover it easily because I would launch our app from my debugger, with the device on the desk, and then pick up my iPad – which caused a couple of quick semi rotations.
It’s The Animation
You will notice from the line of code above, that we are telling the button to be added to the toolbar in an animated fashion, in this case a fade-in. In iOS you can manually animate almost anything, but many of the UIKit calls contain flags (as above) so the framework will perform the default animation for you automatically. I was already thinking that the animation was not so good in this case, the button would quickly fade in while the screen finished rotating. If Chuck Norris was using the app he would be ready to click before the button was there!
So I tried:
[toolbar setItems:items animated:NO];
This resulted in almost no visual difference to the user, and…………..no disappearing toolbar button!