Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MFMailComposeViewController的UINavigationBar未始终显示正确的图像/颜色_Ios_Iphone_Uiimage_Uinavigationbar_Mfmailcomposeviewcontroller - Fatal编程技术网

Ios MFMailComposeViewController的UINavigationBar未始终显示正确的图像/颜色

Ios MFMailComposeViewController的UINavigationBar未始终显示正确的图像/颜色,ios,iphone,uiimage,uinavigationbar,mfmailcomposeviewcontroller,Ios,Iphone,Uiimage,Uinavigationbar,Mfmailcomposeviewcontroller,我正在使用我的应用程序,当点击导航按钮时,它会从特定的UITableView调用MFMailComposeViewController 因为我的应用程序中有主题(12个选项),我首先认为让MFMailComposeViewController产生相同的主题会很好,我直接从代码而不是从故事板创建 在测试我的应用程序时,我注意到每次启动此视图时,NavigationBar图像并不保持一致。在Storyboard中,我在右侧有两个导航栏项,这是通过在该视图中嵌入UIToolbar的UIView以及该U

我正在使用我的应用程序,当点击
导航按钮时,它会从特定的
UITableView
调用
MFMailComposeViewController

因为我的应用程序中有主题(12个选项),我首先认为让
MFMailComposeViewController
产生相同的主题会很好,我直接从代码而不是从故事板创建

在测试我的应用程序时,我注意到每次启动此视图时,
NavigationBar
图像并不保持一致。在Storyboard中,我在右侧有两个导航栏项,这是通过在该视图中嵌入UIToolbar的UIView以及该UIToolbar中的两个导航栏按钮项来实现的。这使我可以让两者相邻

考虑到这一点,我注意到了一种模式。如果单击电子邮件图标,出现的MFMailComposeViewController会有一个导航栏,它会获取相应的图像。如果我点击导航栏中的第二个图标(加号图标),然后再次点击电子邮件图标,UINavigationBar是白色的,因此不会加载图像。我已经输入了nslog,代码被适当地调用以设置UINavigationBar,但这是模式;首先单击其他UINavigationBar按钮项,然后单击电子邮件,UINavigationBar不会显示UIImage。 代码如下:

- (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];
        }];
    }
}
问题

因此,重申一下这个问题:当我通过点击导航栏按钮在应用程序中选择并调用此
MFMailComposeViewController
时,如果我先单击电子邮件按钮,则会显示UIImage,但如果我先单击加号按钮,然后单击电子邮件,则MFMailComposeViewController上不会显示uinavigationbar图像

我想让
UINavigationBar
始终获取所选主题的
UINavigationBar
图像

AppDelegate已经为所选主题和
UINavigationBar的
图像设置了代码,但似乎没有在这里应用。这里有一个小片段:

else if ([self.selectedTheme isEqualToString:@"Simplicity"])
{
    UIImage *navBackgroundImage = [UIImage imageNamed:@"GreenishNav.png"];

    [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
如何确保MFMailComposeViewController的UINavigationBar图像保持选定主题的图像

其他任何一种观点都是完美的;就是这个

奇怪的是,在我的应用程序的其他地方,我从
UITableViewCell
调用另一个
MFMailComposeViewController
,使用完全相同的代码(只是更改主题等),并且每次都保留
UINavigationBar
的图像;只需从这里使用
UINavigationBar
按钮,图像就不会保留

更新:我已经找到了一些复制的步骤。在调用MFMailComposer视图控制器的UINavigationBar按钮所在的视图中,我还有第二个NavigationBar项,允许用户从此处添加条目。这是在故事板中创建的,其中嵌入了UIView和UIToolbar,以及该工具栏中的两个导航栏项目(电子邮件和添加)。如果我单击邮件图标,它将与图像保持一致。但是,如果我点击导航栏中的加号按钮,取消该按钮,然后单击电子邮件图标,当MFMailComposer出现时,它不会显示UINavigationBar图像


任何指导都将不胜感激

你的问题很长,但答案很简单

请参阅这些关于更改
MFMailComposeViewController
的导航栏和色调的堆栈溢出帖子。你可以试试你的情况。但是你的问题不是重复的,所以我在这里指的是相关的帖子

更新部分

  • 其思想是控制任何viewController的
    UINavigationBar
    viewwillbeen
    方法中的外观
  • 下面是这个的例子
  • 这是屏幕截图。
  • 最后,如果你想要样品,你可以检查一下。单身是没有用的。您可以相应地修改它
//试试看

-(void)displayMailComposerSheet
{
    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {

    }
    else
    {
        [[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    }


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

    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {

    }
    else
    {
        picker.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor];
    }

    NSLog(@"%@",Data_Dict);

    [picker setSubject:[NSString stringWithFormat:@"%@",[Data_Dict objectForKey:@"short_name"]]];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@""];

    [picker setToRecipients:toRecipients];

    //  // Attach an image to the email
    //  NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];
    //  NSData *myData = [NSData dataWithContentsOfFile:path];
    //  [picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"];

    // Fill out the email body text
    NSString *emailBody = str_sms;
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}



#pragma mark -
#pragma mark Dismiss Mail/SMS view controller
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    ////NSLog(@"%u",result);


    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {

    }
    else
    {

        [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];

        // Uncomment to change the color of back button
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

        // Uncomment to assign a custom backgroung image
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg_ios7.png"] forBarMetrics:UIBarMetricsDefault];

        // Uncomment to change the back indicator image

        [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@""]];
        [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@""]];

        // Uncomment to change the font style of the title

        NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
        shadow.shadowOffset = CGSizeMake(0, 1);

        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:@"ArialMT" size:18.0], NSFontAttributeName, nil]];

        CGFloat verticalOffset = -4;
        [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
    }


    if(result == 0)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Result" message:@"Mail sending canceled" delegate:Nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if(result == 1)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Result" message:@"Result: Mail saved" delegate:Nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if(result == 2)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Result" message:@"Mail sent" delegate:Nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if(result == 3)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Result" message:@"Mail sending failed" delegate:Nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Result" message:@"Mail not sent" delegate:Nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    [self dismissModalViewControllerAnimated:YES];
}
-(无效)显示邮件编写器工作表
{
如果([[[UIDevice currentDevice]系统版本]浮点值]<7.0)
{
}
其他的
{
[[UINavigationBar外观]setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
MFMailComposeViewController*选择器=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
如果([[[UIDevice currentDevice]系统版本]浮点值]<7.0)
{
}
其他的
{
picker.navigationBar.titleTextAttributes=[NSDictionary Dictionary dictionaryWithObject:[UIColor blackColor]forKey:UITextAttributeTextColor];
}
NSLog(@“%@”,数据记录);
[picker setSubject:[NSString stringWithFormat:@“%@,[Data_Dict objectForKey:@“short_name”]];
//设置收件人
NSArray*toRecipients=[NSArray数组及其对象:@”“;
[picker setToRecipients:toRecipients];
////将图像附加到电子邮件
//NSString*path=[[NSBundle mainBundle]pathForResource:@“rainy”类型:@“jpg”];
//NSData*myData=[NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@“image/jpeg”文件名:@“Rain”];
//填写电子邮件正文文本
NSString*emailBody=str\u短信;
[picker setMessageBody:emailBody isHTML:NO];
[自我呈现ModalviewController:picker动画:是];
[选择器释放];
}
#布拉格标记-
#pragma标记解除邮件/短信视图控制器
-(void)mailComposeController:(MFMailComposeViewController*)控制器未完成结果:(MFMailComposeResult)结果错误:(NSError*)错误{
////NSLog(@“%u”,结果);
如果([[[UIDevice currentDevice]系统版本]浮点值]<7.0)
{
}
其他的
{
[[UINavigationBar外观]设置部分颜色: