I am new to iphone development.I have created a tabbar based application . In the first i want the email composer to be displayed. I am able to display it but the cancel and send button are not working,I don't know where do i go wrong .Please help me out. Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
[self displayComposerSheet];
}
-(void)displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
[[picker navigationBar] setTintColor:[UIColor blackColor]];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail])
{
[picker setToRecipients:[NSArray arrayWithObjects:@"name@gmail.com",nil]];
[picker setSubject:@"Sample"];
}
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
If you are adding only subview of mailcomposser you have to remove it from self.view, In your code you are adding subview and present also,
If you are use only use
[self.view addSubview:picker.view];
than Try with to remove it.I'm still suggest to use
[self.navigationController presentModalViewController:picker animated:YES];
for Present MFMailComposeViewController ,and use
[self dismissModalViewControllerAnimated:YES];
to dismiss it.Set Delegate of MFMailComposeViewController
And Use this Delegate Method
Use this code:
You are presenting the mail composer twice.
Remove the line:
And replace the next line with: