views:

859

answers:

4

I have image picker which collects data for another view controller (TTMessageController from three20) and I want this message composer to appear behind image picker, so when image piker slides out there will be already appeared message controller with pre-filled data.

Code like this

[self.navigationController presentModalViewController:composeController animated:NO];
[picker dismissModalViewControllerAnimated:YES];

and vice-versa wont work at all. What to do? How to present composeController behind already presented picker controller?

Thanks in advance.

A: 

Edit:

Ok I think the problem here is the modal bit, as the iPhone really appears to not like you having 2 views set to modal, or even animating from one modal view to another.

Do they definitely have to be modal? How about adding them to the normal navigation stack?

You could add the message view to the stack first (non-animated) so that it's there when you pop back one.

Try this:

The order in which you add views to the stack affects the order that they will display in when you dismiss them.

This part adds the composeController to the stack and then animates the picker going on top. Use this code to display the picker controller (ie instead of modal dialog):

[self.navigationController pushViewController:composeController animated:NO];
[self.navigationController pushViewController:picker animated:YES];

Then, when you are done with the picker, you can "pop" the view back to the message composer:

[self.navigationController popViewControllerAnimated:YES];

You should now have no references to any modal dialogs remaining in your code. I believe this should work much better than modal, which really is for displaying one view above every other one, not for switching from view to view.

Hope that helps!

h4xxr
It doesn't work, only thing I get is composeController with bugs and no imagePicker at all.
totocaster
Hmm ok, I'll go away and try it out
h4xxr
Does this now sort it after the edit changes?
h4xxr
Unfortunatelly no, because UIImagePickerController is a subclass of UINavigationController and pushing navigation controller (Picker) to another navigation controller (main one) is not supported in Cocoa-Touch.
totocaster
A: 

Actually removing animation from both viewController help.

[picker dismissModalViewControllerAnimated:NO];
[self presentModalViewController:composeNavController animated:NO]; // If YES it crashes

But it's not to iPhone-ish if get what I mean, even fade throw black or just some visual effect will make it look much, much nicer. Technically tho, it works.

totocaster
I think the problem is the modal bit. Have modified my answer...
h4xxr
A: 

Instead of trying to present another viewController behind the picker, you could dismiss the image picker modal view controller, push the Message controller (both with animated:NO), and then use a CATransition to perform your own Cocoa-like animation of the image picker animating off screen.

Jason
That's sounds interesting, but how? I'll really appreciate some kind of help.
totocaster
Roughly: [picker dismissModalViewControllerAnimated:NO]; [self.navigationController pushViewController:messageController animated:NO]; CATransition * t = [CATransition transition]; t.type = kCATransitionMoveIn; t.subtype = kCATransitionFromTop; [[self.navigationController layer] addTransition:t];
Jason
I've tried that, it's not working. Animations seem to conflict with each other and it seems I'm doing exact same thing what Cocoa Touch tries to do for me while dismissing modalView from the screen.
totocaster
A: 

You need to split these animations up so they don't execute in the same runloop. I've run into a situation where the OS does not like dismissing and presenting modal views back to back.

Try this:

- (void)myCallbackMethod{

[picker dismissModalViewControllerAnimated:YES];
[self performSelector:@selector(presentMessage) withObject:nil afterDelay:0.25];


}

- (void)presentMessage{

[self.navigationController presentModalViewController:composeController animated:YES];

}
Corey Floyd