Objective C MFMailComposeViewController取消 - >取消按钮不起作用

时间:2018-01-18 13:46:15

标签: ios objective-c

rounded cancel button请查看代码和附图。取消按钮不起作用。如果我单击该按钮,那个模式单独关闭。它不会触发" mailComposeController:didFinishWithResult" function ..我是Objective c IOS的​​新手。请帮我解决这个问题。我搜索了堆栈溢出。但我的问题没有解决

#import "ViewController.h"
#import <MessageUI/MFMailComposeViewController.h>

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *send;
- (IBAction)sendMail:(id)sender;
@end

@implementation ViewController 
MFMailComposeViewController* controller;

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a     nib.
 controller= [[MFMailComposeViewController alloc] init];
 controller.mailComposeDelegate = self;
 }


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }


 - (IBAction)sendMail:(id)sender {

[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
if (controller)         [self presentViewController:controller animated:YES completion:nil];

 }

 - (void)mailComposeController:(MFMailComposeViewController*)controller
      didFinishWithResult:(MFMailComposeResult)result
                    error:(NSError*)error;
 {
 NSLog(@"Coming here");
 if (result == MFMailComposeResultSent) {
    NSLog(@"Mail It's away!");
 }
 if (result == MFMailComposeResultFailed) {
    NSLog(@"Mail Error!");
 }
 if(result == MFMailComposeResultCancelled){
    NSLog(@"Mail Error!");

 }
 if(result == MFMailComposeResultSaved){
    NSLog(@"Mail Saved!");

 }
 [controller dismissViewControllerAnimated:YES completion:nil];
 return;
 }
 [![Screen shot][1]][1]@end

1 个答案:

答案 0 :(得分:1)

除了解雇行动表之外,这个取消按钮什么都不做。如果你想摆脱邮件编辑,你必须在左上角按取消,这会在底部显示一个操作表,其中包括选项删除草稿,保存草稿和取消。删除草稿并保存草稿将关闭邮件编辑器,并将调用委托函数。如果用户意外点击了顶部的取消按钮,则取消按钮实际上将关闭操作表以保存邮件编写器不被解雇