Search code examples
objective-cxcode4

Changing views after sending an email


I'm having trouble thinking of ways to change views after hitting "send" when in email mode. I have a main view that is a form that the user fills out, that info then populates the email. Now when I hit "send" I don't want the user to go back to the form page but a new one.

Thoughts? Thanks!


Solution

  • Add MFMailComposeViewControllerDelegate to your view controller interface.

    then make the current view controller the delegate when initializing the ``

     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
    

    you will be notified of the status of the mail in the method

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
        // Notifies users about errors associated with the interface
        switch (result)
        {
            case MFMailComposeResultCancelled:
    //          message.text = @"Result: canceled";
                break;
            case MFMailComposeResultSaved:
                          break;
    
            case MFMailComposeResultSent:
    
                break;
    
            case MFMailComposeResultFailed:
            {
                UIAlertView *FailedAlert= [[UIAlertView alloc]initWithTitle:@"Mail could not be sent" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
                [FailedAlert show];
                [FailedAlert release];  
                break;
            }
            default:
                NSLog(@"Hit default case in the switch");
                break;
        }
        [self dismissModalViewControllerAnimated:YES];   
    }
    

    Here you should be able to load a new view based on your choice and result.