iOS7中的MFMailComposeViewController自定义

use*_*321 3 iphone objective-c ios ios7

我在iOS7中自定义MFMailComposeViewController时遇到问题.我正在尝试隐藏和删除标题,因为我有一个自定义的导航外观,我想进入邮件视图控制器.我正在使用它,它在iOS6上工作正常但是第一次在iOS7上打开时不会工作.当我打开视图并取消邮件然后再次打开控制器时,它可以继续工作.问题是第一次出现邮件控制器.这是我正在使用的代码:

if ([MFMailComposeViewController canSendMail]) {

    UIView* parentView = [self showProgress];

    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;

    if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"CourierNewPS-BoldMT" size:1], UITextAttributeFont, [UIColor whiteColor],UITextAttributeTextColor, nil]];

    [controller setToRecipients:[NSArray arrayWithObject:[LNController shared].profile.email]];
    [controller setSubject:NSLocalizedString(@"APPSTORE_NAME", nil)];
    NSData* energyData = [[self createEnergyCSVFile] dataUsingEncoding:NSUTF8StringEncoding];
    NSData* timeData = [[self createTimeCSVFile] dataUsingEncoding:NSUTF8StringEncoding];
    [controller addAttachmentData:energyData mimeType:@"text/csv" fileName:NSLocalizedString(@"ENERGY", nil)];
    [controller addAttachmentData:timeData mimeType:@"text/csv" fileName:NSLocalizedString(@"TIME", nil)];

    [[[[controller viewControllers] lastObject] navigationItem] setTitle:@""];
    [self presentViewController:controller animated:YES completion:nil];

    [self hideProgress:parentView];

}  
Run Code Online (Sandbox Code Playgroud)

以前有人经历过吗?任何帮助都是极好的.

Mar*_*ski 5

您必须直接在自定义代码上设置MFMailComposeViewController.以下是我的一个应用程序的示例:

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    // Fix UI -- Add your custom UI here
    [mailViewController.navigationBar setTintColor:[UIColor whiteColor]];
    [mailViewController.navigationBar setBarTintColor:[UIColor whiteColor]];
    // Set params
    [mailViewController setToRecipients:@[@"e-mail@email.com"]];
    [mailViewController setSubject:NSLocalizedString(@"Feedback", @"Feedback")];
    [self presentViewController:mailViewController animated:YES completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }];
}
Run Code Online (Sandbox Code Playgroud)

编辑:这是一个仅限iOS 7的应用程序,所以还添加了所需的检查,以便它不会在iOS 6上崩溃

  • setBarTintColor似乎不适合我.我使用的是iOS 7.1.其他人有同样的问题吗? (5认同)