我之前见过几个问题,例如this,但由于缺乏一个已接受的答案以及根据需要实施了所有问题,我仍然继续面对如下问题:
我显示邮件编辑器,但点击取消时,作曲家视图冻结。我认为这是由于保存/删除草稿操作表显示在可见框架之外。是的我已将mailComposeDelegate设置为呈现视图控制器,并已阅读几个类似的问题,其中用户未处理(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
委托以取消取消作曲家。我也处理了这个问题,但我似乎无法弄清楚为什么动作表不会出现在我的通用应用程序的iPhone版本的屏幕的可见区域中。以模块方式将邮件编辑器呈现为NSLogged的视图控制器的视图框架是(0,0,320,480)。我的应用程序是通用的&邮件作曲家在iPad上完美运行。以下是在iPhone模拟器5.1上运行的作曲家视图外观的截图: -
这是显示作曲家的代码:
-(IBAction)mailButtonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"Subject"];
[controller setMessageBody:@"Test" isHTML:YES];
[controller setToRecipients:nil];
if(controller) {
[self presentModalViewController:controller animated:YES];
[controller release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:5)
为什么不尝试删除代码,并在线上教程时重试,例如:
在这些情况下,你总是忘记了工作所需的一行简单代码,因此遵循教程可以帮助我确保所有必要的代码都在那里。
请尝试使用此代码:
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
答案 1 :(得分:2)
在此处使用此完整代码作为消息:
·H
#import <MessageUI/MFMailComposeViewController.h>
@interface EmailViewController : UIViewController<MFMailComposeViewControllerDelegate>
的.m
-(IBAction)Email {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"contact_aaron@easy.com", nil]];
[composer setSubject:@"Idea for Basic Calculator"];
[composer setMessageBody:@"My idea is:" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:composer animated:YES];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error with message" message:[NSString stringWithFormat:@"Error %@", [error description]] delegate:nil cancelButtonTitle:@"Try Again Later!" otherButtonTitles:nil, nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
}
答案 2 :(得分:2)
您尝试的设备可能由于某种原因无法发送邮件
您可以使用[MFMailComposeViewController canSendMail]
答案 3 :(得分:0)
在
中应用此功能-(void)displayComposerSheet
if(composer != nil) {
[composer release];
composer = nil;
}
为此对象赋值后
[picker composer];
答案 4 :(得分:0)
您似乎没有使用自动参考计数(ARC)。您过早发布邮件撰写控制器。在被解雇后释放它。
删除此行:[控制器发布]
if(controller) {
[self presentModalViewController:controller animated:YES];
/// remove this: ----> [controller release];
}
并在此处发布此控制器
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
[controller release]; // <---- add this
}
答案 5 :(得分:0)
将此添加到您的(所有)UIViewControllers以检查您的iPhone是否耗尽或内存。这可以解释奇怪的行为,即mailComposerSheet发布了你的基本viewController,所以mailComposerDelegate是零。
- (void)didReceiveMemoryWarning
{
NSLog(@"didReceiveMemoryWarning");
[super didReceiveMemoryWarning];
}