gpt4 book ai didi

ios - 未调用 MFMailComposeViewController 委托(delegate)方法

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:38 25 4
gpt4 key购买 nike

我有某种操作表 UIView,它在点击其中的一个按钮后调用 MFMailComposeViewController,MFMailComposeViewController 被调用并成功呈现,但是当我点击取消时它不会消失,有时会崩溃,我知道这是一个已知问题,但我已经尝试了所有已知的修复程序,但它对我不起作用。那是我的代码:

发送反馈.h:

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface SendFeedback : UIView <UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>

//Useless code to the problem.

@property (nonatomic, retain) MFMailComposeViewController *feedBackComposer;

@end

发送反馈.m:

- (void)baseInit
{
//Useless code to the problem.

feedBackComposer = [[MFMailComposeViewController alloc] init];
[feedBackComposer setMailComposeDelegate:self];
[feedBackComposer setToRecipients:[NSArray arrayWithObject:@"info@getibox.com"]];
[feedBackComposer setMessageBody:@"" isHTML:NO];
[feedBackComposer setSubject:@"What I Love About iBox"];
}

调用 Composer : - (void)sendFeedbackComposer { [self.window.rootViewController presentViewController:feedBackComposer animated:YES completion:nil];

关闭它:

- (void)mailComposeController:(MFMailComposeViewController *)feedBackComposer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
//This method doesn't get called.

[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

NSLog(@"Error: %@", error);
}

编辑: 所以,这个问题中提供的所有答案都是正确的,都是我的错。我想做的是:我有一个 UINavigationController,其中包含一个 UITableView,该 View 中的 cells 应该触发一个操作表,它是一个 UITableView 通过添加它作为一个 subview,就像前面的一样,这个 View 也包括 cells 并且其中一个将执行一个操作和它正在调用一个 MFMailComposeViewController,它被调用但没有成功关闭,即使我已经设置了它的委托(delegate)并且所有方法都正确,问题的原因是调用 的方式MFMailComposeController,我首先从 super View 中删除了那个小 UITableView 然后显示了 MFMailComposeController,所以当我关闭邮件编辑器时它崩溃了甚至没有给出结果,这让我把崩溃的原因与委托(delegate)方法混淆了,骗我吧。这是代码:

- (void)removeView
{
if (self) {
[UIView animateWithDuration:0.3
animations:^{backgroundView.alpha = 0;}
completion:^(BOOL finished){

[UIView animateWithDuration:.3
animations:^{self.frame = CGRectMake(0, 568, 320, 568);}
completion:^(BOOL finished){[self removeFromSuperview];}];
}];
}
}
- (void)sendFeedbackComposer
{
feedBackComposer = [[MFMailComposeViewController alloc] init];
[feedBackComposer setMailComposeDelegate:self];
[feedBackComposer setToRecipients:[NSArray arrayWithObject:@"info@getibox.com"]];
[feedBackComposer setMessageBody:@"" isHTML:NO];
[feedBackComposer setSubject:@"What I Love About iBox"];

[self.window.rootViewController presentViewController:self.feedBackComposer animated:YES completion:nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 2: //That's the index of the MailComposer caller.
[self removeView];
[self sendFeedbackComposer];
break;
case 6:
[self removeView];
break;
default:
break;
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[feedBackComposer.presentingViewController dismissViewControllerAnimated:YES completion:nil];

NSLog(@"Error: %@", error);
}

感谢 Stefan Atanasov、Jim 和 Vitaly S。

最佳答案

您确定没有调用委托(delegate)方法吗?我做了一个测试并调用了它,但是要关闭邮件编辑器使用这样的代码:

[feedBackComposer dismissViewControllerAnimated: YES completion: nil];

另外,在 View 实现中实现委托(delegate)真的很奇怪,而不是在 View Controller 中实现

关于ios - 未调用 MFMailComposeViewController 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21352135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com