gpt4 book ai didi

iphone - 在 MFMailComposeViewController 中设置第一响应者?

转载 作者:行者123 更新时间:2023-12-03 18:42:16 24 4
gpt4 key购买 nike

我正在使用 Apple 的 MailComposer从我的应用程序内发送电子邮件的示例应用程序(OS 3.0 功能)。是否可以使用 MFMailComposeViewController 将“收件人”、“主题”或“正文”字段设置为第一响应者?

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

我注意到 MFMailComposeViewController 文档说:

“重要提示:邮件撰写界面本身不可自定义,并且您的应用程序不得对其进行修改。此外,在呈现该界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但编程更改将被忽略。因此,您必须在呈现界面之前设置内容字段的值。”

但是,我不关心自定义界面。我只想设置firstResponder。有什么想法吗?

最佳答案

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

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

//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 的 View 以及您想要成为第一响应者的字段传递到函数中。

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];

关于iphone - 在 MFMailComposeViewController 中设置第一响应者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1690279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com