gpt4 book ai didi

iphone - MFMailComposeViewController 导航栏按钮被禁用

转载 作者:行者123 更新时间:2023-12-03 21:04:27 26 4
gpt4 key购买 nike

我使用 MFMailComposeViewController 在我的应用程序中发送邮件。但是,当当前邮件撰写 View Controller 时,所有导航按钮都被禁用(选择邮件地址屏幕中的后退按钮除外),我必须使用主页按钮退出应用程序。有人有想法吗?这是屏幕截图: Screen shot 2


代码:

- (void)shareVieEmail{    if ([MFMailComposeViewController canSendMail]) {        MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];        mailViewController.mailComposeDelegate = self;        [mailViewController setSubject:@"Test subject"];        [mailViewController setMessageBody:@"Mail message body" isHTML:NO];        NSData *imageData = [NSData dataWithContentsOfFile:photourl];        [mailViewController addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example_photo"];        [self presentModalViewController:mailViewController animated:YES];    } else {        [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:@"Device is unable to send email in its current state" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];    }}

委托(delegate)方法:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{    switch (result)    {        case MFMailComposeResultCancelled:            //NSLog(@"Result: canceled");            break;        case MFMailComposeResultSaved:            //NSLog(@"Result: saved");            break;        case MFMailComposeResultSent:        {            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];            [alert show];        }            break;        case MFMailComposeResultFailed:        {            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];            [alert show];        }            break;        default:            //NSLog(@"Result: not sent");            break;    }    if (error) {        [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:[NSString stringWithFormat:@"ERROR:%@", [error userInfo]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];    }    [self dismissModalViewControllerAnimated:YES];}

在头文件中,我声明实现 MFMailComposeViewControllerDelegate。

最佳答案

我遇到了完全相同的问题。我花了一段时间才弄清楚这一点,但毫不奇怪,它归结为自定义的 UIBarButtonItem

我打赌你的 UIBarButtonItem.h 中有一个方法

-(void)setEnabled:(BOOL)enabled ;

其实现如下所示:

-(void)setEnabled:(BOOL)enabled {
if (self.customView) {
if ([[self.customView.subviews objectAtIndex:0] isKindOfClass:[UIButton class]]) {
((UIButton*)[self.customView.subviews objectAtIndex:0]).enabled = enabled;
}
}
}

这会导致问题,因此一旦您注释掉此方法,您的问题就会消失。

关于iphone - MFMailComposeViewController 导航栏按钮被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8860736/

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