我正在使用Apple的MailComposer示例应用程序从应用程序内部发送电子邮件(OS 3.0功能)。是否可以使用MFMailComposeViewController将“收件人”,“主题”或“正文”字段设置为第一响应者?
换句话说,该行为是:用户按下呈现邮件 View 的按钮(presentModalViewController)。出现邮件 View 时,光标将放置在其中一个字段中,并且键盘将打开。
我注意到MFMailComposeViewController文档说:
“重要:邮件撰写界面本身不可自定义,不能由您的应用程序修改。此外,在显示该界面之后,您的应用程序将无法再对电子邮件内容进行更改。用户仍可以使用接口(interface),但是程序性更改将被忽略。因此,在显示接口(interface)之前,您必须设置内容字段的值。”
但是,我不在乎自定义界面。我只想设置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/