Iphone 是否在MFMailComposeViewController中设置第一响应者?
我正在使用苹果的示例应用程序从我的应用程序中发送电子邮件(OS3.0功能)。是否可以使用MFMailComposeViewController将“收件人”、“主题”或“正文”字段设置为第一响应者 换句话说,行为是:用户按下一个显示邮件视图的按钮(presentModalViewController)。显示邮件视图时,光标将放置在其中一个字段中,键盘将打开 我注意到MFMailComposeViewController文档中说: “重要提示:邮件合成界面本身是不可自定义的,应用程序不能对其进行修改。此外,在显示界面后,不允许您的应用程序对电子邮件内容进行进一步更改。用户仍然可以使用界面编辑内容,但编程更改将被忽略。因此,您必须在显示界面之前设置内容字段的值。”Iphone 是否在MFMailComposeViewController中设置第一响应者?,iphone,email,iphone-sdk-3.0,mfmailcomposeviewcontroller,Iphone,Email,Iphone Sdk 3.0,Mfmailcomposeviewcontroller,我正在使用苹果的示例应用程序从我的应用程序中发送电子邮件(OS3.0功能)。是否可以使用MFMailComposeViewController将“收件人”、“主题”或“正文”字段设置为第一响应者 换句话说,行为是:用户按下一个显示邮件视图的按钮(presentModalViewController)。显示邮件视图时,光标将放置在其中一个字段中,键盘将打开 我注意到MFMailComposeViewController文档中说: “重要提示:邮件合成界面本身是不可自定义的,应用程序不能对其进行修改
但是,我不关心自定义接口。我只想设置firstResponder。有什么想法吗?您可以尝试在控制器本身上调用becomeFirstResponder。如果这不起作用,您可以尝试在调试器中获取mail compose视图的子视图列表,直到找到您熟悉的文本字段或文本视图然后可以专门编写代码以在代码中设置响应者状态,这可能类似于以下内容(我不知道这是否可行,但这是一个示例):
您可以使这些字段成为第一响应者
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];
如果将以下方法添加到类中
//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的视图与要成为第一响应者的字段一起传递到函数中
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];
我喜欢简化代码并使其易于理解。 只需将以下代码放在后面:
[self-presentModalViewController:mailComposer动画:是]
for (UIView *subview in mailComposer.view.subviews) {
NSString *className = [NSString stringWithFormat:@"%@", [subview class]];
//NSLog(@"%@", className); // list the views - Use this to find another view
//The view I want to set as first responder: "_MFMailRecipientTextField"
if ([className isEqualToString:@"_MFMailRecipientTextField"]){
[subview becomeFirstResponder];
break; // Stop search.
}
}
在iOS 6中,无法再在AFAICT的任何文本字段上设置first responder。浏览视图层次结构最终会显示UIRemoteView,其中的子视图会被模糊处理。非常好-花了数小时试图找到解决方法。只需将RecipientTextField更改为MFRecipientTextField即可。是吗这是否可以用于应用商店提交,或被视为未记录的API?我不确定这是否可以用于应用商店提交,我仅将其用于内部应用程序。您好,上述解决方案对我不起作用,它仅显示UINavigationTransitionView、UILayoutContainerView、UIButtonLabel、UINavigationButton等作为类名当我在方法中打印它们时。它没有给出一个名为MFRecipientTextField等的子视图类。你知道怎么了吗?顺便说一句,收件人视图是“MFMailComposer指定视图”而不是“RecipientTextField”,至少对我来说是这样。我相信由于使用了远程视图控制器,这种技术在iOS 6中不再有效。我很想听听更新的应用程序这不起作用,因为递归是向下导航视图层次结构所必需的。