ailComposeViewController中设置第一个响应

ailComposeViewController中设置第一个响应

本文介绍了在MFMailComposeViewController中设置第一个响应程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用苹果的示例应用程序从内部发送电子邮件我的应用程序(OS 3.0功能)。可以使用MFMailComposeViewController将To,Subject或Body字段设置为第一个响应者?

I'm using Apple's MailComposer example application to send email from within my application (OS 3.0 functionality). Is it possible to set the To, Subject, or Body fields as first responder with MFMailComposeViewController?

换句话说,行为将是:用户按下一个按钮,邮件视图(presentModalViewController)。当邮件视图被显示时,光标被放置在一个字段中,键盘打开。

In other words, the behavior would be: the user presses a button which presents the mail view (presentModalViewController). When the mail view is presented, the cursor is placed in one of the fields and the keyboard opens.

我注意到MFMailComposeViewController文档说:

I notice the MFMailComposeViewController documentation says:

重要信息:邮件合成界面本身不可自定义,不得由应用程序修改。此外,在显示界面后,您的应用程序不允许进一步更改电子邮件内容,用户仍然可以使用界面对内容进行编辑,但编程更改将被忽略,因此您必须在显示界面之前设置内容字段的值。

但是,我不在乎定制界面。我只想设置firstResponder。任何想法?

However, I don't care about customizing the interface. I just want to set that firstResponder. Any ideas?

推荐答案

您可以使这些字段成为第一个响应者。

You are able to make these fields become the first responder.

如果您添加以下方法到您的类...

if you add the following method to your class...

//Returns true if the ToAddress field was found any of the sub views and made first responder
//passing in @"MFComposeSubjectView"     as the value for field makes the subject become first responder
//passing in @"MFComposeTextContentView" as the value for field makes the body become first responder
//passing in @"RecipientTextField"       as the value for field makes the to address field become first responder
- (BOOL) setMFMailFieldAsFirstResponder:(UIView*)view mfMailField:(NSString*)field{
    for (UIView *subview in view.subviews) {

        NSString *className = [NSString stringWithFormat:@"%@", [subview class]];
        if ([className isEqualToString:field])
        {
            //Found the sub view we need to set as first responder
            [subview becomeFirstResponder];
            return YES;
        }

        if ([subview.subviews count] > 0) {
            if ([self setMFMailFieldAsFirstResponder:subview mfMailField:field]){
                //Field was found and made first responder in a subview
                return YES;
            }
        }
    }

    //field not found in this view.
    return NO;
}

然后,在呈现MFMailComposeViewController之后,将MFMailComposeViewController的视图传递到函数中你要成为第一个响应者的领域。

Then, after you present the MFMailComposeViewController, pass the MFMailComposeViewController's view into the function along with the field you want to become first responder.

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

/*Set up the mail composer*/

[self presentModalViewController:mailComposer animated:YES];
[self setMFMailFieldAsFirstResponder:mailComposer.view mfMailField:@"RecipientTextField"];
[mailComposer release];

这篇关于在MFMailComposeViewController中设置第一个响应程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:03