dismiss mail controller view on pressing cancel button in action sheet
I have a table view with four sections. The cell of one of the sections contains the email address. When i click on that cell i open mail view controller. Now when i click on the cancel button which is present on the navigation bar, an action sheet appears in which there are three buttons. One of those three buttons is cancel button. Now i want to return back to the table view when i click on this cancel button of action sheet. i have tried all the possible methods including
-(void)mailComposeController:
(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
method of MFMailComposeViewController
delegate.
Please help me out. Here is my code :
if(indexPath.section == 2)
{
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc]init];
[mailcontroller.mailComposeDelegate self];
[mailcontroller setToRecipients:[[NSArray alloc]initWithObjects:record.contactemail, nil]];
[self presentViewController:mailcontroller animated:YES completion:nil];
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
First add this two delegate in your .h
file like bellow...
@interface yourViewController : UIViewController<
MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate>{
///your code..
}
and give delegate to self like bellow...
MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc]init];
mailcontroller.mailComposeDelegate = self;
and try my this method ...
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent)
{
NSLog(@"nn Email Sent");
[AppDelegate showAlert:@"Email Sent"];
}
if([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
[self dismissViewControllerAnimated:YES completion:nil];
else
[self dismissModalViewControllerAnimated:YES];
// [self dismissViewControllerAnimated:YES completion:nil];
}
try this
链接地址: http://www.djcxy.com/p/94544.html下一篇: 按操作表中的取消按钮,关闭邮件控制器视图