草庐IT

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

coder 2024-01-22 原文

请找到代码和附图。那个取消按钮不起作用。如果我单击该按钮,该模式将单独关闭。它不会触发“mailComposeController:didFinishWithResult”函数。我是 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

最佳答案

伙计,这个取消按钮除了关闭操作表外什么都不做。如果您想摆脱邮件编辑器,您必须按左上角的取消,这会在底部显示一个操作表,其中包含删除草稿、保存草稿和取消选项。删除草稿和保存草稿将关闭邮件编辑器并调用委托(delegate)函数。取消按钮实际上会关闭操作表,以防止邮件编写器在用户不小心单击顶部的取消按钮时关闭

关于ios - Objective C MFMailComposeViewController 取消 -> 取消按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48322855/

有关ios - Objective C MFMailComposeViewController 取消 -> 取消按钮不起作用的更多相关文章

随机推荐