I am working with my app that calls up the MFMailComposeViewController
from a particular UITableView
when a navigationBarButton
has been tapped.
Because I have themes in my app (a choice of 12), I first thought it would be good to have the MFMailComposeViewController
come up with the same theme and I'm creating this directly from code and not from the Storyboard.
While testing my app, I'm noticing that the NavigationBar
image does not remain consistent each and every time this view is launched. Within Storyboard, I have two navigation bar items on the right side which is implemented by having a UIView with a UIToolbar embedded in that view and finally the two navigation bar button items in that UIToolbar. This allows me to have both next to each other.
With this in mind, I've noticed a pattern. If I click on the Email icon, the MFMailComposeViewController that comes up has a NavigationBar that takes the appropriate image. If I tap the second icon in the navigation bar (Plus icon) and then go and tap the Email icon again, the UINavigationBar is white and therefore it doesn't load the image. I've put in NSLogs and the code is getting called appropriately for setting the UINavigationBar, but this is the pattern; click on the other UINavigationBar Button item first and then click on the Email and the UINavigationBar does not show the UIImage.
Here's the code:
- (IBAction)savePDFAndEmail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"An email"];
NSString *emailBody = @"Hello";
[mailer setMessageBody:emailBody isHTML:NO];
mailer.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
[[mailer navigationBar] setTintColor:[UIColor whiteColor]];
[self presentViewController:mailer animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];
}
}
Problem
So, to reiterate the issue: when I select and call up this MFMailComposeViewController
in the app by tapping the navigation bar button, the UIImage is shown if I click on the Email button first, but if I click on the Plus button and then the email, the uinavigationbar image is not shown on the MFMailComposeViewController.
What I want here is for the UINavigationBar
to always take the selected theme's UINavigationBar
image.
The AppDelegate already sets the code for the selected theme and the UINavigationBar's
image, but it seems to not get applied here. Here's a little snippet:
else if ([self.selectedTheme isEqualToString:@"Simplicity"])
{
UIImage *navBackgroundImage = [UIImage imageNamed:@"GreenishNav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
What can I do to ensure the MFMailComposeViewController's
UINavigationBar
image remains that of the selected theme?
Every other view is perfectly fine; it's just this one.
The weird thing is the fact that elsewhere in my app, I call another MFMailComposeViewController
from a UITableViewCell
with the exact same code (just changing the subject, etc) and that keeps the Image of the UINavigationBar
every time; it's just from here with the UINavigationBar
Button that the image does not remain.
Update: I've found some steps to reproduce this. In the view where I have the UINavigationBar button that calls the MFMailComposerViewController, I also have a second NavigationBar item that allows a user to add an entry from here. That is created in Storyboard with a UIView and a UIToolbar embedded within that view and the two NavigationBar items (Email and Add) inside that toolbar. If I click on the mail icon, it appears consistently with the image. However, if I tap the plus button in the nav bar, cancel that and then click on the email icon, it doesn't display the UINavigationBar image when the MFMailComposer comes up.
Any guidance would really be appreciated.