Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

iphone - Change title of MFMailComposeViewController

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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...