iPhone - Dismissing previous ModalViewControllerAnimated:YES then poping a new ModalViewControllerAnimated:YES - fail - iphone

I have a main window that pops a modal view controller. When done in this modal view controller, it returns to the main window then dismisses itself.
Then the main windows pops a new Modal view controller with animated=YES.
The problem is that the dismiss call that is done inside the first modalviewcontroller applies to both and SecondController is never shown.
Putting the first dismiss before or after the parent call does not change anything.
If first dismiss is set wih animate= NO, everything works fine. But I need the animation.
Main.m
- (void) entry {
FirstController *nextWindow = [[FirstController alloc] initWithNibName:#"theNIB" bundle:nil];
nextWindow.caller = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[nextWindow release];
[navController release];
}
- (void) thingsDoneInFirstModalController:(OBJECT)returnValue retval2:(OBJECT2)returnValue2 {
[self display2ndController];
}
- (void) display2ndController {
SecondController *nextWindow;
nextWindow = [[SecondController alloc] initWithNibName:#"NIB2" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[nextWindow release];
}
1st ModalViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController dismissModalViewControllerAnimated:YES];
[self.caller thingsDoneInFirstModalController:theResult retval2:someMoreResult];
}
What may I do ?
I don't want to catch anything in view....Disapear...
Why does the dismiss colides as they are not called from the same navigation controller ?

The reason is likely the animation when you dismiss it. Try showing the second modal window using the performSelector:withObject:afterDelay:, a method inherited from NSObject. Reference here.

Related

can't dismiss presentModalViewController

i have two view controllers in iphone application.
1.) FirstVC
2.) SecondVC
In my FirstVC i have one button. By tapping on that button i opened SecondVC in presentModalViewController. look bellow code.
- (IBAction)buttonClicked:(id)sender
{
SecondVC *secondVC = [SecondVC alloc] initWithNibName:#"SecondVC" bundle:nil];
[self.navigationController presentModalViewController:secondVC animated:YES];
}
now moved to SecondVC. On SecondVC i have create navigation bar as well as "cancel" button as a leftBarButtonItem. i set a button clicked event on cancel button. in that method i want to dismiss SecondVC. bellow method is in SecondVC. look bellow code.
- (void)cancelButtonClicked
{
[self dismissModalViewControllerAnimated:YES];
}
This code dosen't work. i can't dismiss SecondVC by this code. Please suggest another tricks.
Change the button code to this..
- (IBAction)buttonClicked:(id)sender
{
SecondVC *secondVC = [SecondVC alloc] initWithNibName:#"SecondVC" bundle:nil];
[self presentViewController:secondVC animated:YES completion:NULL];
}
on cancelButtonClick
-(void)cancelButtonClicked {
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
You are sending the dismissModalViewControllerAnimated: message to the wrong object.
Since you presented the modal view controller through the navigation controller, then you should call:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
This will work on iOS 5 and newer. In case you are targeting only iOS 5 and newer, you could also think of using the newer methods that are available on it to manage modal view controllers:
– presentViewController:animated:completion:
– dismissViewControllerAnimated:completion:
but I don't think this is mandatory.
If you want to support iOS 4 and older, you should add a property to your modal view controller:
#interface SecondVC : UIViewController
#property (nonatomic, weak/assign) UIViewController* presentingController;
...
#end
and set it before displaying the controller modally:
- (IBAction)buttonClicked:(id)sender
{
SecondVC *secondVC = [SecondVC alloc] initWithNibName:#"SecondVC" bundle:nil];
secondVC.presentingController = self.navigationController;
[self.navigationController presentModalViewController:secondVC animated:YES];
}
then you would use:
[self.presentingController dismissModalViewControllerAnimated:YES];
try this for present secondVC...
[self presentModalViewController:secondVC animated:YES];
Please Replace your code with the following... code
- (IBAction)buttonClicked:(id)sender
{
SecondVC *secondVC = [SecondVC alloc] initWithNibName:#"SecondVC" bundle:nil];
[self presentModalViewController:secondVC animated:YES];
}
- (void)cancelButtonClicked
{
[self dismissModalViewControllerAnimated:YES];
}

UINavigation : How to push view from presented modal view

I am having problem in navigation of views.
I have VC say, Login, which I am calling from another VC like :
- (IBAction) btnAction
{ Login * login = [[Login alloc] init];
[self.navigationController pushViewController:login animated:YES];
}
in login VC there are two buttons say, Register and Forget Password, that calls another VC, RegisterVC and ForgetPassVC accordingly.
- (IBAction) btnRegisterNow : (id) sender
{
aRegister = [[Register alloc] initWithNibName:#"Register" bundle:nil];
[self.navigationController pushViewController:aRegister animated:YES];
}
- (IBAction) btnForgotPassword : (id) sender
{
forgotPassword = [[ForgotPasswd alloc] initWithNibName:#"ForgotPasswd" bundle:nil];
[self.navigationController pushViewController:forgotPassword animated:YES];
}
My Problem :
When I call Login by [self.navigationController pushViewController:login animated:YES]; every thing works fine.
But in some VCs I need to display login page as [self presentModalViewController:login animated:YES]; At this time the two buttons, Register and Forget Password does not work. On button click nothing happens.
What is the problem ? I think bocz of I have added Login as modal view not a pushViewConterller ??? if so then how can I accomplish this task ?
hope question is clear.
Thanks...
When you present your controller modally, they aren't in a navigation controller. You should write
UINavigationViewController *nvc = [[UINavigationViewController alloc] initWithRootViewController:login];
[login release];
[self presentModalViewController:nvc animated:YES];
[nvc release];
I think you should push the Forgot password & Register VCs also as modal controllers. Have you tried that?
When you are doing
[self presentModalViewController:login animated:YES]; in this case your view controller get passed and now when you try to implement [self.navigationController pushViewController:forgotPassword animated:YES]; it did ont work because you dont have navigation controller.
Is it necessary to present your login as modal view.
Then use this code:-
- (IBAction) btnAction
{
Login *login=[[[Login alloc]initWithNibName:#"Login" bundle:nil]autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:login]autorelease];
[[self navigationController] presentModalViewController:navController animated:YES];
}
Now your forgot and register btn action will called and will navigate to the that corresponding page.
Present navigation controller with your login view controller as root controller.Check below code.
UINavigationController *navController = [UINavigationController alloc] initWithRootController:loginController];
[self presentModalViewController:navController];
[navController release];

iphone loss of tabbar during uimodaltransition

Okay, working on a transition between a view with a tabbar and another view which is to be an information/about view. I have the code to transition from the view with tabbar and to transition back to previous view, but during the transition back I lose the tabbar at the bottom. Not sure exactly how to approach this with the tabbar in the MainWindow.xib
E.g.:
(IBAction)backButtonPressed:(id)sender
{
TablesViewController *tvc = [[TablesViewController alloc] initWithNibName:#"TablesView" bundle:nil];
tvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tvc animated:YES];
[tvc release];
}
Thanks,
np
Try presenting the modal transition from the containing instance of UITabBarController and not the UIViewController the action was triggered from.
- (IBAction)backButtonPressed:(id)sender
{
TablesViewController *tvc = [[TablesViewController alloc] initWithNibName:#"TablesView" bundle:nil;
tvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.tabBarController presentModalViewController:tvc animated:YES];
[tvc release];
}
I had the exact same problem, did a ugly solution:
- (IBAction)backButtonPressed:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}

iPhone - Display smoothly 2 successive modal view controller

I'm searching a way to be able to display one modal view controller after another one, and make the second appear while the first is disapearing.
The problem is that the dismiss call that is done inside the first modalviewcontroller applies to both and SecondController is never shown.
Putting the first dismiss before or after the parent call does not change anything.
If first dismiss is set wih animate= NO, everything works fine. But I need the animation.
I planned to do that this way, but the problem is that the dismiss call that is done inside the first modalviewcontroller applies to both and SecondController is never shown.
I don't understand why because each modal view has its own navigationcontrollers, so they shouldn't collide.
I tried another way by showing the second modal view with a NSTimer after 0.5 sec, but it's not satisfying : the second appears when the first has completely disapeared. Not smooth at all... If I set the delay less than 0.5 sec, the second modal view never shows up. And using such a timer to make this does not seem to be a good way of coding.
Main.m
- (void) entry {
FirstController *nextWindow = [[FirstController alloc] initWithNibName:#"theNIB" bundle:nil];
nextWindow.caller = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[nextWindow release];
[navController release];
}
- (void) thingsDoneInFirstModalController:(OBJECT)returnValue retval2:(OBJECT2)returnValue2 {
[self display2ndController];
}
- (void) display2ndController {
SecondController *nextWindow;
nextWindow = [[SecondController alloc] initWithNibName:#"NIB2" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[nextWindow release];
}
1st ModalViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController dismissModalViewControllerAnimated:YES];
[self.caller thingsDoneInFirstModalController:theResult retval2:someMoreResult];
}
Do you know a way to make this possible (make the second view appears while the first one is disappearing), with some code for example ?
Thank you.
Try creating some dummy ViewController, and present your second one using it.

Modal view controller returning

I have the following code where I display a view controller within a navigation controller.
Just for the test I display it for 3 seconds and then dismiss it.
What is happening is that it disappearing - and then reappearing after a second or so.
What am I doign wrong?
- (void) test
{
[myNavCtrl dismissModalViewControllerAnimated:YES];
}
- (void) viewDidAppear:(BOOL)animated
{
MyViewController *ctrl = [[MyViewController alloc] init];
[ctrl setDelegate:self];
myNavCtrl = [[UINavigationController alloc] initWithRootViewController:ctrl];
[myNavCtrl setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:myNavCtrl animated:NO];
[ctrl release];
[myNavCtrl release];
[self performSelector:#selector(test) withObject:nil afterDelay:3];
}
The viewWillAppear method is called every time the controller's view appears so you've created a loop. The view appears, it calls the modal view which covers the calling view. When the modal view disappears, the calling view controller's viewWillAppear gets called again. Lather, rinse, repeat.