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

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.

Related

Modal disappearing after rotating UISplitViewController

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

Multiple MODAL VIEW controller change base modal to FULL SCREEN after ROTATION

This has been troubling me for quite a while, and I have done so much research on this, but could't find an answer. My first time posting a question here, please correct/forgive me if I make a mistake.
Environment: iPad, iOS 6.0
Problem: Base modal view change to full screen after rotation.
Description: I have a full screen application running currently showing a modal view controller. From the showing modal view, I display another modal view by doing:
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated:YES];
//[self presentViewController:vc animated:YES completion:NULL];
While the second view is appearing, and I rotate the iPad device. The base(first) modal view becomes full screen, and the topmost(second) modal view stays in formSheet style. (rotate correctly)
I can fix this by adding modal view to navigationController, but I want to keep it in modal view.
Any one knows a fix? I believe this person here is having the same problem:
ios 6 Incorrect modal view size after rotation
Btw, everything works fine in iOS 5. Apple changed the way rotation works in iOS 6.
Thanks,
-peter
I found a solution for this problem. Set the last modal view's presentation style to UIModalPresentationCurrentContext before you present it.
Like this:
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:YES];
This solves the base modal view change size after rotate the iPad screen.
Originally answered by people on Apple Dev forum.
I had the exact same issue and used the code in iOS 6: Parent modal's modalPresentationStyle ignored after rotation worked like a charm

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.

self.navigationController pushViewController:SomeViewController animated:YES is not giving the correct view after the orientation changed

I'm having an wired issue on my iPad app on home screen, it has four different views on home page cause it has an arabic layout for each portrait and landscape view and I'm drawing each view with code. Each of them contain different layout.
The problem is when i navigate from the portrait home screen to another screen with
[self.navigationController pushViewController:ArticleListsProtrait animated:YES] code
then rotate the device and get back to home with
[self.navigationController popToViewController:SomeViewController animated:YES] code
it gives me the correct layout but when i push the view controller from landscape screen and rotate the device and pop the view controller with same code it gives me the landscape layout of the home screen.
Also there is something i found that on first case the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation" method is called but on the second case it is not being called. i am new to iphone/ipad development and i am not getting any idea to solve this issue.
--thanks in advance

iPad Full Screen Modal View over TabBarController?

On a TabBar-based application on the iPad, is there a way to present a modal on top of it in "FullScreen"?
I have a LANDSCAPE ONLY APP (if that makes a difference) and the item I want to currently present modally I would like to present full screen, filling the entire screen just to clarify. I can present it in "PageSheet" fine, and "FormSheet" is all right, after a few button adjustments on the modal view nib, but once I try "FullScreen", the background goes white (TabBar still there, though), and if I retry hitting the button (without restarting the simulator), it won't respond.
The view where the button is located to present the modal view is CountryViewController.m and has the action:
-(IBAction) showNewModal:(id)sender {
modalContent.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
modalContent.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:modalContent animated:YES];
}
This code works fine without the TabBar, I've realized. I've looked for hours for something to add to this code or even in the AppDelegate.h and .m files but so far, it's either unresponsive (oddly enough without showing an error) or the aforementioned white space.
in my experience the problem comes from presenting the modal from the wrong controller.
[self.tabBarController presentModalViewController:modalContent animated:YES];
should work
If you work with iOS 4 a (maybe) beter options is to use:
[[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:modalContent animated:YES];

Resources