在MFMailComposeViewController中设置第一响应者?
我使用Apple的MailComposer示例应用程序从我的应用程序(OS 3.0功能)中发送电子邮件。是否可以使用MFMailComposeViewController将To,Subject或Body字段设置为第一响应者?在MFMailComposeViewController中设置第一响应者?
换句话说,行为将是:用户按下提供邮件视图的按钮(presentModalViewController)。当显示邮件视图时,光标放置在其中一个字段中并打开键盘。
我注意到MFMailComposeViewController文件说:
“重要提示:邮件撰写界面本身不是定制的,不得通过您的应用程序进行修改此外,呈现的界面后,你的应用程序不允许对电子邮件内容做进一步修改,用户仍然可以使用界面编辑内容,但忽略编程变更,因此必须在显示界面之前设置内容字段的值。
但是,我不在乎定制界面。我只想设置那个firstResponder。有任何想法吗?
回答:
您可以尝试在控制器本身上调用becomeFirstResponder。如果这不起作用,您可以尝试在调试器中获取邮件撰写视图的子视图列表,直到找到熟悉的文本字段或文本视图,然后您可以专门用代码设置响应者状态,这可能看起来像这(我不知道这是否会工作,但它是一个例子):
[[[[mailcomposer.view.subviews objectAtIndex:3] subviews] objectAtIndex:2] becomeFirstResponder]
回答:
你可以使这些领域成为第一响应者。
,如果你将以下方法添加到您的类...
//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 animated:YES];
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上设置第一响应者。浏览视图层次结构最终会显示一个UIRemoteView,这里的子视图被混淆了。
以上是 在MFMailComposeViewController中设置第一响应者? 的全部内容, 来源链接: utcz.com/qa/258535.html