无法关闭 iPhone 中的电子邮件编辑器视图?

发布于 2024-08-27 00:19:12 字数 1018 浏览 13 评论 0原文

我是 iPhone 开发新手。我创建了一个基于选项卡栏的应用程序。首先,我希望显示电子邮件编辑器。我可以显示它,但取消和发送按钮不起作用,我不知道哪里出了问题。请帮助我。这是我的代码。

- (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:@"[email protected]",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];

 }

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:@"[email protected]",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];

 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

擦肩而过的背影 2024-09-03 00:19:12

您正在向邮件编辑器展示两次。

删除行:

[self.view addSubview:picker.view];

并将下一行替换为:

[self.navigationController presentModalViewController:picker animated:YES];

You are presenting the mail composer twice.

Remove the line:

[self.view addSubview:picker.view];

And replace the next line with:

[self.navigationController presentModalViewController:picker animated:YES];
终止放荡 2024-09-03 00:19:12

如果您仅添加 mailcomposser 的子视图,则必须将其从 self.view 中删除,
在您的代码中,您要添加子视图并也显示,

如果您仅使用 [self.view addSubview:picker.view];
尝试将其删除。

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
    [controller.view removeFromSuperview];

 }

我仍然建议对

Present MFMailComposeViewController 使用 [self.navigationControllerpresentModalViewController:pickeranimated:YES];

并使用 [selfdismissModalViewControllerAnimated: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.

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
    [controller.view removeFromSuperview];

 }

I'm still suggest to use

[self.navigationController presentModalViewController:picker animated:YES]; for Present MFMailComposeViewController ,

and use [self dismissModalViewControllerAnimated:YES]; to dismiss it.

递刀给你 2024-09-03 00:19:12

使用此代码:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
[controller setToRecipients:toRecipients];
[controller setTitle:@"Contact Us"];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
     [self becomeFirstResponder];
     NSString *strMailResult;
     switch (result)
     {
        case MFMailComposeResultCancelled:
        strMailResult = NSLocalizedString(@"E-Mail Cancelled",@"");
        break;
        case MFMailComposeResultSaved:
        strMailResult = NSLocalizedString(@"E-Mail Saved",@"");
        break;
        case MFMailComposeResultSent:
        strMailResult = NSLocalizedString(@"E-Mail Sent",@"");
        break;
        case MFMailComposeResultFailed:
        strMailResult = NSLocalizedString(@"E-Mail Failed",@"");
        break;
        default:
        strMailResult = NSLocalizedString(@"E-Mail Not Sent",@"");
        break;
     }

     UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ISO Audit",@"") message:strMailResult delegate:self  cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil];
     [alertView show];
    [self dismissModalViewControllerAnimated:YES];
}

Use this code:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
[controller setToRecipients:toRecipients];
[controller setTitle:@"Contact Us"];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{
     [self becomeFirstResponder];
     NSString *strMailResult;
     switch (result)
     {
        case MFMailComposeResultCancelled:
        strMailResult = NSLocalizedString(@"E-Mail Cancelled",@"");
        break;
        case MFMailComposeResultSaved:
        strMailResult = NSLocalizedString(@"E-Mail Saved",@"");
        break;
        case MFMailComposeResultSent:
        strMailResult = NSLocalizedString(@"E-Mail Sent",@"");
        break;
        case MFMailComposeResultFailed:
        strMailResult = NSLocalizedString(@"E-Mail Failed",@"");
        break;
        default:
        strMailResult = NSLocalizedString(@"E-Mail Not Sent",@"");
        break;
     }

     UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ISO Audit",@"") message:strMailResult delegate:self  cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil];
     [alertView show];
    [self dismissModalViewControllerAnimated:YES];
}
倾城月光淡如水﹏ 2024-09-03 00:19:12

设置 MFMailComposeViewController 的委托

MFMailComposeViewController *mailcomposer = [[MFMailComposeViewController alloc]init];

mailcomposer.mailComposeDelegate = self; 

并使用此委托方法

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
}

Set Delegate of MFMailComposeViewController

MFMailComposeViewController *mailcomposer = [[MFMailComposeViewController alloc]init];

mailcomposer.mailComposeDelegate = self; 

And Use this Delegate Method

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文