更改MFMailComposeViewController的标题 [英] Change title of MFMailComposeViewController

查看:126
本文介绍了更改MFMailComposeViewController的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用MFMailComposeViewController进行应用内电子邮件,但是我无法更改标题。作为默认,它显示标题中的主题,但我想设置标题为别的东西。我如何做到这一点?



我试过:

  controller.title = @反馈; 

但没有起作用。



这是我的代码:

   - (IBAction)email {
NSArray * array = [[NSArray alloc] initWithObjects: @myemail@gmail.com,nil];
MFMailComposeViewController * controller = [[MFMailComposeViewController alloc] init];
[[控制器导航栏] setTintColor:[UIColor colorWithRed:0.36 green:0.09 blue:0.39 alpha:1.00]];
controller.mailComposeDelegate = self;
controller.title = @反馈;
[controller setSubject:@Long subject];
[controller setMessageBody:@
isHTML:NO];
[controller setToRecipients:array];
[self presentModalViewController:controller animated:YES];
[控制器释放];
[array release];
}

- (void)mailComposeController:(MFMailComposeViewController *)控制器didFinishWithResult:(MFMailComposeResult)结果错误:(NSError *)错误{
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}


解决方案

您可以设置不同的标题对于您的MFMailComposeViewController,使用单行,如此。

  ... 
[self presentModalViewController:controller animated:YES ]。 //现有行
[[[controller viewController] lastObject] navigationItem] setTitle:@SomethingElse];
...

但是,此实现有效依赖于MFMailComposeViewController的未记录功能。您正在访问私有类(_MFMailComposeRootViewController)的navigationItem并将其标题更改为邮件主题以外的内容。我回应Art Gillespie的情绪,因为你不应该这样做,很可能被苹果评论者拒绝做这样的事情。此外,此过程可能会在iPhone操作系统的任何细微点发布中完全改变,可能会导致用户崩溃,直到您可以发布更新以修复此行为。



这个决定取决于你,但是如果你还想采取这些不利的步骤,那就是你如何做。


I'm using MFMailComposeViewController for in-app email in my app, but I'm not able to change the title. As default it's showing the subject in the title, but I would like to set the title to be something else. How can I do that?

I've tried:

controller.title = @"Feedback";

but it didn't work.

Here's my code:

- (IBAction)email {
    NSArray *array = [[NSArray alloc] initWithObjects:@"myemail@gmail.com", nil];
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    [[controller navigationBar] setTintColor:[UIColor colorWithRed:0.36 green:0.09 blue:0.39 alpha:1.00]];
    controller.mailComposeDelegate = self;
    controller.title = @"Feedback";
    [controller setSubject:@"Long subject"];
    [controller setMessageBody:@""
                        isHTML:NO];
    [controller setToRecipients:array];
    [self presentModalViewController:controller animated:YES];
    [controller release];
    [array release];
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [self becomeFirstResponder];
    [self dismissModalViewControllerAnimated:YES];
}

解决方案

You can set a different title for your MFMailComposeViewController with a single line, like so.

...
[self presentModalViewController:controller animated:YES]; // Existing line
[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"SomethingElse"];
...

However, this implementation effectively relies on undocumented features of MFMailComposeViewController. You're accessing the navigationItem of a private class (_MFMailComposeRootViewController) and changing its title to something other than the mail subject. I echo Art Gillespie's sentiment in that you should not do this and are very likely to be rejected by the Apple reviewers for doing something like this. In addition, this process could change completely in any minor point release of the iPhone OS, possibly causing crashes for your users until you can release an update to fix the behavior.

The decision is up to you, though, and if you still want to take these unrecommended steps, that is how you do it.

这篇关于更改MFMailComposeViewController的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆