0
votes

This is the situation:

I have a tab bar with 2 tabs. Tab01 and Tab02. In Tab01 I have a button which pushes repVC:

    repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:repVC animated:YES];
    [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
    [repVC release];

Inside repVC I have another button which pushes an MFMailComposerViewController:

    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    [self presentModalViewController:mail animated:YES];
    [mail release];

The problem is: when mailView is shown(in Tab01) and I click Tab02, then back to Tab01, the mailView is hidden and even if I click the email button again, the view won't be presented.

So what I have is:

Tab01.view -> repVC.view -> mail.view 

For repVC, I use this line when I push the view so that even if I go switch tabs, that view will still be activated:

   [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];

But I can't do the same for mail because tabController is declared in another class which I cannot import. So I can't access the tabController and set the view for Tab01.

Hope the edit helped the understanding.

3

3 Answers

1
votes

Hmm,

I still would suggest to use a Navigationcontroller. Would make things way easier, is conform to apple guidelines and suggestions and is pretty fast implemented. (Just create a Navigationcontroller, put the View of Tab1 as main view and hand it over to the TabbarController. Then for the mailView use [self.navigationController pushViewController:mail animated:YES]; Then the navcontroller "saves" the present view for you when u switch tabs)

But if for some Reason you have to use a modalViewcontroller you could either just deactivate the tabbar while the ModalView is shown or try to implement a switch or a simple if...else case in your ViewWillAppear where u check what screen to load. Then Clean out the Window and load the right screen.

Hope you get the idea of what I mean, sometimes my way of writing seems to confuse people. ^^

0
votes

A little more information would be great.

How did u set up your TabbarController?

How do u push the new view? Within a UINavigationController? If not, then do it with a navController, he should save the actual state of view and your problem should be solved.

If u already use a navController please post your ViewDidLoad and ViewWillAppear of the Viewcontroller of Tab 1

0
votes

As @Amandir points out you could probably solve your problems by using a UINavigationController. I get a feeling that you are trying to abuse the modal view controller concept a bit and that's why it doesn't work as you expect. When you use presentModalViewController:animated: the intention should be that you are displaying a view that is modal, i.e. the user must interact and dismiss the modal view before she can continue.

What the paragraph above means that when you present a modal view controller it shouldn't be possible to use the tab bar. Since you are using the word push I'm guessing that you would like change the view of Tab01 while still being able to use the functionality of the tab bar. The problem is that there isn't any built-in method of pushing view controllers besides UINavigationController. persentModalViewController:animated: should only be used in case where you want a modal view, which on the iPhone means a full screen view.

The easiest way would probably be to use an UINavigationController and hide the navigation bar. Then you would get the functionality I think you are after. The other option is to manually add and remove sub views.

[self.view addSubview:repVC.view];

and

[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];

You can use block animations if you want some fancy transitions.