Modal disappearing after rotating UISplitViewController - ios

I have a strange problem UISplitViewController. I have a button in my master view controller which opens a modal view when tapped (using a simple storyboard segue).
But the modal view disappears when I rotate the iPad, but only when rotating from portrait to landscape. My master view controller is hidden in portrait, like in the native Mail application.
If I'm in landscape (when the master is always visible) and open my modal, rotating the device works correctly and my modal stays on screen.
I tried manually triggering the segue programmatically, if I call performSegueWithIdentifier: on the splitViewController, rotating works both ways. But I was wondering if this was fixable in a simpler way because I have other buttons displaying modals in the master view controller and I don't want to do an IB action for each one and lose the advantages of storyboard segues.

unfortunately it is like that, when your ipad is on portrait mode, you have a popover of your master, it is not the master in another shape. What means that you are presenting a modal using this popover as presentingViewController, so when you move from portrait to landscape the method splitViewController:willShowViewController will make your popover nil as you can see:
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
So I understand that is acceptable that your modal is going with it. So, with this you understand why when you put your action an call the performSegueWithIdentifier: on your splitViewController it doesn't happen, your modal is no longer connected with your popover.
So you may ask why it doesn't happen when you move from landscape to portrait.. and the reason is splitViewController:willHideViewController, it hides the viewController it doesn't remove it, so your modal is always connected.
So, unfortunately there is no solution and you will have to perform the actions by code..
I hope it helps,
Roberto

Related

Show/hide dismiss button in a UIPopoverPresentationController

I have a UINavigationController that I'm presenting in a popover using UIPopoverPresentationController.
The navigation controller must be presented when displayed in both popover and fullscreen mode (as the adaptive system so chooses.)
I have all this working.
The problem comes when I want to show/hide a dismiss button in the navigation controller depending on how it's being presented. I can't seem to determine whether I'm popover or fullscreen?
The WWDC stuff talks about returning a new navigation controller in presentationController:viewControllerForAdaptivePresentationStyle - but that's no good in my case as my navigation controller may have had other controllers pushed onto it and so cannot simply be swapped out.
Any pointers would be most welcome.
Thanks
[UPDATE] So the presenting view controller gets traitCollectionDidChange: and if it's horizontal compact then I poke into the presentedViewController->childViewControllers[0].navigationItem.leftBarButtonItem and set it to 'close'. But boy does this feel hacky.
[UPDATE2] So this link helps Close button on adaptive popover but the dismiss button is not then cleared when it switches back out to regular width.

NavigationBar contents disappear on pop from view with prefersStatusBarHidden = YES

I have a fairly straightforward setup in my iPhone app, with a navigation controller and a view controller. The view controller has a title, and for most of my views, pushing other view controllers works as expected: the title is used as the label for the "back" button on the navigation bar, and the new view is shown. After the new view has been popped from the stack, the old view is shown with its title.
However, as soon as the pushed view controller implements prefersStatusBarHidden with the return value YES, the title in the navigation bar is gone after this view is popped from the stack - it remains empty and doesn't even display my custom rightbarbuttonitem.
Additionally, doing this in landscape instead of portrait does not show this behaviour - the title is displayed correctly. If you encounter this issue in portrait, you could turn the phone to landscape and back to portrait again, and the title and everything else will reappear in place.
I am unsure if this was already there in previous versions of iOS, but I am currently seeing it with iOS 8.
I had the same issue and the workaround for me was this:
In the view controller that is having prefersStatusBarHidden set to YES add:
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
}
I believe that is because prefersStatusBarHidden is a app wide setting, not per view controller.
You may be able to get around this by adding to the pushed view controllers ViewWillDisappear method
- (void)viewWillDisappear:(BOOL)animated {
[UIApplication sharedApplication].statusBarHidden = NO;
}

Presented views on iOS 6 disappear. How do I fix this?

I have two views that I present from a view controller: one for settings, one for a device log. When I run the app on an iPad and present the view, then rotate the device, the view disappears.
If I present the view (using a button) in portrait (either one) and rotate it, it disappears. If I then present the view again, it reappears, and then rotates correctly.
Why does this happen? What can I do to fix it?
Thanks for any responses.
UPDATE: This only occurs if I first present the view in portrait mode. If I present it in landscape mode first, it rotates just fine and doesn't disappear.
In my master view controller's viewDidLoad:
self.logViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"LogViewController"];
[self.logViewController setModalInPopover:YES];
[self.logViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self.logViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
My method called when the Log button is pressed:
- (void)showInfoView:(id)sender
{
[self presentViewController:self.logViewController animated:YES completion:NULL];
}
I have realized what I was doing wrong. I was presenting the presented view controller from my Master view in a SplitViewController. By presenting it from the Detail view, the problem was solved.

Problems presenting modal view controller over UISplitViewController

I have a requirement to present a modal ViewController over a UISplitViewController (i.e. obscuring both the master and detail views, when in landscape).
My code is based on Apple's sample code for Multiple Detail Views, and I've added the presentModalViewcontroller to didFinishLaunching.
To present the modal view, I've used this,
[self.window.rootViewController presentModalViewController:entryView animated:NO];
and this,
[[self.splitViewController.viewControllers objectAtIndex:0] presentModalViewController:entryView animated:NO];
...and both behave in the same way (explained below).
The modal view is presented as I intend, i.e. the view pops up and covers the UISplitView as required. All good so far.
However, as a consequence of presenting the modal view, iOS calls willHideViewController for the obscured UISplitViewController master view. I guess that's reasonable, as the master view is being hidden.
The real problem occurs when the modal view is dismissed, because willShowViewController is NOT called to undo the changes made in willHideViewController (i.e. remove the popover button added to the detail view when the master view was hidden).
This unwanted popover button then sits there, on my Detail view navbar, generally causing a nuisance.
Any thoughts on how to get willShowViewController to be called when the modal view is dismissed, or to otherwise fix this issue would be appreciated.

Contents of UIPopover change to random orientation when Modal View is visible and iPad rotated

I have a UITableView within a navigation controller shown within a popover. When you press a bar button from within the popover (on a detail view), it shows a modal view. If you rotate the iPad with the popover visible and the modal view on top of that, the popover's content changes to a seemingly random orientation as shown below.
Any idea what's going on here?
UPDATE:
I'm trying to implement a solution, maybe there's a better way. When the modal view is dismissed, I send an NSNotification from - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error to the popover's owner.
When I press cancel, the button is visibly pressed but nothing happens after that and the screen becomes unresponsive. However, rotation still occurs properly.
It would seem that I'm dismissing the popover before the modal view is dismissed. I don't really know any other way of doing this, you're continued help is appreciated.
I had to completely reload the popover and its view controllers. This is the only way I could mask the problem, not solve it, because this seems to be a bug in iOS 3.2.
Have you tried to dismiss the popover and then redisplay it? The UIPopoverController documentation is straightforward in saying that it will often fail to rotate a popover, and suggests redisplaying it as the only solution. I suspect that since your modal view is on top of the view from which the popover was displayed, the popover's controller is not updating its position & orientation.

Resources