My app has two windows, mainWindow (for almost all views) and loginWindow (just for login view).
When applicationDidEnterBackground I switch mainWindow with loginWindow:
[self.loginWindow makeKeyAndVisible];
[self.mainWindow setHidden:YES];
When I came back in app the loginWindow with its views is shown. That works just fine.
However I have a problem with modalView presentation in mainWindow.
After applicationDidEnterBackground windows are switched again. After going back to mainWindow the modalView is not visible.
Method self.modalViewController gives me the exact modalView that was presented earlier, but is not visible anymore.
I've tried to show this modalView again with no luck like this:
[self presentModalViewController:self.modalViewController animated:NO];
How can I "re-present" this hidden modalView again?
Probably you need some logic here. Like Crio stated, dismiss it when entering the background, but remember it in a property or smth. else.
// applicationDidEnterBackground
self.savedModalViewController = self.modalViewController;
[self.mainWindow dismissModalViewControllerAnimated:NO];
// after login but before presenting the mainWindow again
[self.mainWindow presentModalViewController:self.savedModalViewController animated:NO];
If your showing the "modalView" modally, then on applicationDidEnterBackground dismiss the modal view:
[self.mainWindow dismissModalViewControllerAnimated:NO];
and then the modal should work fine.
Related
I've a weird problem... in a tabbar application, in the tabBarController i call:
[myController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
self presentModalViewController:myController animated:YES];
myController get presented and everything work but when i try to dismiss it (from within myController) with:
[[self presentingViewController] dismissModalViewControllerAnimated:YES];
It does the dismiss animation, i can almost see my tabBarController active view when suddenly myController re-appear.
The only way to make it work is using the default transition style:
UIModalTransitionStyleFlipHorizontal
Every other animation, or even trying to dismiss myController without animations cause that problem.
After the dismiss call, viewWillDisappear and viewDidDisappear of myController get called.
viewWillAppear and viewDidAppear of myController DON'T get called when it re-appear.
Calling again the dismiss function does nothing.
I'm almost sure nothing is presenting myController again, it's like it's simply not going away completely.
I've tried replacing myController with a fresh new controller with and empty view, nothing changed.
It's sounds like a stupid problem but i really can't understand it...
PS: I'm using iOS5, storyboard, ARC, it's an iphone app, i'm using the simulator (can't try on an iphone at the moment)
Is that dismiss being called from within the modally presented VC? Try this:
[self dismissModalViewControllerAnimated:YES];
This has been asked a dozen times on this site, but I haven't found an answer that works for me. I have an iPad application with a UISplitViewController on the root level that is created programmatically. Inside the view that is being displayed in the right hand pane, triggered by user interaction, a UINavigationController is programmatically created and presented to the user. Here is that code:
listenerController = [[UINavigationController alloc] initWithRootViewController:listenerView];
[listenerController.navigationBar setTintColor:[UIColor colorWithRed:185.0f/255.0f green:80.0f/255.0f blue:0.0f/255.0f alpha:1.0f]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[listenerController setModalPresentationStyle:UIModalPresentationFormSheet];
[listenerController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[listenerController setModalInPopover:YES];
}
[self presentModalViewController:listenerController animated:YES];
[listenerController release];
This does create the view controller properly, but when it is displayed the iPad is forced back into portrait view regardless of what orientation I have the iPad in. Then when I dismiss the modal window, it will rotate back.
I already have shouldAutorotateToInterfaceOrientation in the viewcontroller of the righthand pane set to YES, and I even tried adding this to the main app delegate class without any luck. It doesn't seem like I should have to subclass UINavigationController just to override the shouldAutorotateToInterfaceOrientation method.
Am I calling presentModalViewController from the wrong object? I've tried [self presentModalViewController ...] as well as [self.parentViewController presentModalViewController ...] with the same results.
I'm assuming that the self in your code example is the right-view (detail) view controller. You need to call presentModalViewController from the root UISplitViewController.
So let's say I have a viewController named homeViewController, and another view controller named listViewController
I display listViewController on top of homeViewController as a modal.
If the user clicks the off button, and then comes back to the app the modalViewController is gone.
ListViewController *listViewController = [[ListViewController alloc] init];
[self presentModalViewController:listViewController animated:NO];
[listViewController release];
Note: Application doesn't startup from scratch when this occures and the previous state is still visible
I'm assuming that by "off button" you mean the user locks the iDevice.
I just tried this in one of my apps and the modal view controller is still there after unlocking. My guess would be that it's something unrelated to the code you have posted. I would check your - (void)applicationWillResignActive:(UIApplication *)application method in your app delegate class and see if there's anything there that would dismiss the modal view controller.
Here is what the problem was.
When the user locks the screen I remove homeViewController from window
[homeViewController removeFromSuperview];
When user starts the app again I do
[windows addSubview:homeViewController];
that brings homeViewController on top of its modeal
I have a situation where I am performing some initialization in an App. Upon first startup I have to present an EULA with an I Agree/I Don't Agree button selection. When the I Agree selection is made I display a modal view which prompts for a username and password. This all works fine. The problem is that after the username and password are verified and the modal view is dismissed. I am left with the EULA view still being displayed on the screen rather than the base table view of the App. I do the following in the EULA viewcontroller code:
- (IBAction)didAgree:(id)sender {
LoginViewController *lvc=[[[LoginViewController alloc] init] autorelease];
lvc.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:lvc animated:YES];
[self.view removeFromSuperview];
}
If I move the last line (removeFromSuperview) to before the presentModal call then, of course, the Login view does not display.
In the login view controller code I have this after the login button is pressed:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self parentViewController].view removeFromSuperview];
If I run with this code, the modal view disappears and the table view appears briefly before disappearing with the EULA view remaining on the screen. If I comment out the second statement, then I never see the table view.
I know this I am missing something incredibly obvious but I am at a loss and have been stuck on this for quite a while.
I think the problem is here:
[self presentModalViewController:lvc animated:YES];
Mainly the self there. This means that you present the login screen modally from what self is: your EULA-ViewController. You can't remove the EULA screen now.
I suggest presenting the login screen first, maybe either all grayed out or not showing anything at all, and the presenting the EULA modally from it.
I am migrating my app code base to iPhone SDK 4. In one of the screens I use
-(IBAction) LoadSearch {
MySearchViewController *mySearchController=[[MySearchViewController alloc] initWithNibName:#"MySearchViewController" bundle:nil];
[self.navigationController presentModalViewController:mySearchController animated:YES];
}
That launches the ModalViewController. While the Modal is open, if the user clicks home button, the application goes to suspended state.
If I relaunch the application, immediately after launch the Modal becomes invisible. It seems like the Modal goes to the background of navigationController views.I can see the modal when I rotate the iphone to landscape mode (the modal is being rotated appropriately).
Has any one seen this issue before? Any suggestions are appreciated.
Solved this issue my self.
I was calling the [window addSubview:tabBarController.view] in applicationDidBecomeActive.
So, this resulted in adding tabBarController.view to the window and any modalViewControllers are pushed to background.