I have some questions:
1) When you say "created my own UITabBarController" do you mean that you subclassed UITabBarController?
2) How is the call made to present the modal view controller? Is there a button or something that is being tapped that makes a call to present the modal view controller?
You say that the controllers "are on the main window" and that when you present the modal view you "bring the tab bar controller view to front". This confuses me. The view controllers should "belong" to the tab bar controller.
I created a small project and had it work for me so here's what I did:
1) I created a subclass of UITabBarController:
@interface MyTabBarController : UITabBarController
{
}
- (IBAction)presentModalView:(id)sender;
- (void)dismissModalview;
@end
@implementation MyTabBarController
- (IBAction)presentModalView:(id)sender
{
MyModalViewController* myModalView = [[MyModalViewController alloc] initWithNibName:@"ModalView" bundle:nil];
[myModalView setTbc:self];
[self presentModalViewController:myModalView animated:YES];
}
- (void)dismissModalview;
{
[self dismissModalViewControllerAnimated:YES];
}
@end
2) Then for my modal view controller I created a subclass of UIViewController:
@interface MyModalViewController : UIViewController
{
MyTabBarController* tbc;
}
@property (retain) MyTabBarController* tbc;
- (IBAction)returnToTabBar:(id)sender;
@end
@implementation MyModalViewController
@synthesize tbc;
- (IBAction)returnToTabBar:(id)sender;
{
[tbc dismissModalview];
}
@end
3) I dragged a tab bar controller into the MainWindow.xib, set its File's Owner to MyTabBarController, and added view controllers to both tabs (I set the background colors of each to a different color using the inspector). In the second tab's view controller, I added a button and set its target to be the action "presentModalView:" in MyTabBarController.
4) I created a new xib that contains a view called ModalView and set its File's Owner to MyModalViewController. I set the background color of the view to a different color from the two above and added a button to the view. I set the button's target to the action "returnToTabBar:" in MyModalviewController.
Obviously, I had to add the tab bar view to the subview of window in the app delegate. This worked for me and presented a modal view controller when I was on the second tab and when I dismissed it I was returned to the second tab in the tab bar controller.
I hope this helps!