0

I'm adding TabBarItem (Email) dynamically. When I finish with my email, I'm calling 'dismissModalViewControllerAnimated' but it's simply dismissing mail view. How do I unload the view controller?

in my email view controller I'm doing following:

- (void)viewDidLoad => I would like to unload this view controller
{
    [super viewDidLoad];
    [self showEMail:nil]; => this display and dismisses email (I'm not calling present.. and dismiss... in a row. I'm using delegate methods to present and dismiss, which is fine.)
                              [self presentModalViewController:picker animated:YES];
                              [self dismissModalViewControllerAnimated:YES];

}

after selecting my tab bar item, it's loading view controller(Lets say 'ABC View controller') which is presenting my mail modal controller. mail modal controller is being dismissed properly. but I would like to come back to previously selected tab item after unloading the 'ABC view controller'. is it possible? or am i doing something wrong here?

Thanks in advance

Rama

Krishna
  • 231
  • 4
  • 13

2 Answers2

0

Rama, your question is hard to understand. maybe you need to use delegation for the view controller you are presenting.

In your code, calling [self presentModalViewController...] and [self dismissModalViewController...] in a row doesn't make sense.

You shall call the [self presentModalViewController...] in the first place, make the presenting view controller as the delegate (picker.delegate = self, for instance)

let the modal view controller do its business including exiting (like user hits cancel, close or whatever), then call the delegation method (something like [delegate didFinish...] or [delegate didCancel...]

now it's the presenting view controller's turn to response to the delegation method calling, you can do the modal view controller dismissing here

Note: many UIKit classes practice this pattern, such as UIAlertView, UIActionSheetView, MPMoviePlayerViewController, etc. You shall check them and make your own

Chris Chen
  • 5,307
  • 4
  • 45
  • 49
  • Apologies for not making it clear. I'm not calling present.. and dismiss... in a row. I'm using delegate methods to present and dismiss, which is fine. but how do I unload my view controller? – Krishna Apr 15 '12 at 08:45
  • after selecting my tab bar item, it's loading view controller(Lets say 'ABC View controller') which is presenting my mail modal controller. mail modal controller is being dismissed properly. but I would like to come back to previously selected tab item after unloading the 'ABC view controller'. is it possible? or am i doing something wrong here? – Krishna Apr 15 '12 at 08:49
  • you want to move back to other Tab Bar? – Chris Chen Apr 15 '12 at 13:51
  • yes, also I need to re-launch the modal presenter whenever they click on tab item. I've solved this by using select index and viewwillappear method as mentioned below. Thanks for your suggestions. cheers – Krishna Apr 15 '12 at 21:04
0

I've solved problem by using ViewWiilAppear method to display mail modal presenter.

and i'm selecting the index of tab bar controller after dismissing mail modal presenter.

self.tabBarController.selectedIndex =0;

This solved my problem.

Cheers

Krishna
  • 231
  • 4
  • 13