views:

170

answers:

2

HI,

I am new to iphone development.I have created the tabbar programmatically and sets five views in the tabbar. Now i want to load an email application view when i clicked the tabbar.This works properly.When i clicked the next tabbar and come back to the email view, i am able to see the normal view and not the Email view.Only one time i am able to see my mail application.I have mail application in the viewDidLoad method. So please guide me.

Here is my code,

   - (void)viewDidLoad {

        [super viewDidLoad];

        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
        mail.mailComposeDelegate = self;
        if ([MFMailComposeViewController canSendMail]) {
        [mail setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]];
        [mail setSubject:@"Title"];
        [self presentModalViewController:mail animated:NO];

                     }
        [mail release];

}

Thanks.

+2  A: 

viewDidLoad only runs after the nib file has been loaded, which is once the first time the viewController is shown and then once after any memory warnings are sent.

You want to use viewDidAppear: instead which is called every time after the viewController comes into view.

Brandon Bodnár
+1  A: 

If you use viewDidAppear method it will be keep on calling the mail view.So use viewWillAppear method.

Warrior